From e5c32dda7cb58e1d327eefd06c2f718f93eb643f Mon Sep 17 00:00:00 2001 From: Lucas Teles Date: Fri, 21 Oct 2022 19:54:50 -0300 Subject: [PATCH 01/37] Add Swagger Schema Filter --- README.md | 16 +- .../StronglyTypedIdConverter.cs | 6 + src/StronglyTypedIds/EmbeddedSources.cs | 10 + .../SourceGenerationHelper.cs | 12 ++ .../Guid/Guid_SwaggerSchemaFilter.cs | 13 ++ .../Templates/Int/Int_SwaggerSchemaFilter.cs | 13 ++ .../Long/Long_SwaggerSchemaFilter.cs | 13 ++ .../NewId/NewId_SwaggerSchemaFilter.cs | 13 ++ .../NullableString_SwaggerSchemaFilter.cs | 14 ++ .../String/String_SwaggerSchemaFilter.cs | 14 ++ .../GuidIdTests.cs | 23 +++ .../IntIdTests.cs | 21 ++ .../LongIdTests.cs | 21 ++ .../MassTransitNewIdTests.cs | 21 ++ .../NullableStringIdTests.cs | 21 ++ .../StringIdTests.cs | 21 ++ .../StronglyTypedIds.IntegrationTests.csproj | 3 +- .../Types/GuidId.cs | 5 + .../Types/IntId.cs | 5 + .../Types/LongId.cs | 5 + .../Types/NewIdId.cs | 5 + .../Types/NullableStringId.cs | 5 + .../Types/StringId.cs | 5 + ...urce=StronglyTypedIdConverter.verified.txt | 6 + ...ngType=Guid_implementations=0.verified.txt | 92 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 92 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 93 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 93 +++++++++ ...ingType=Int_implementations=0.verified.txt | 92 +++++++++ ...ingType=Int_implementations=2.verified.txt | 92 +++++++++ ...ingType=Int_implementations=4.verified.txt | 93 +++++++++ ...ingType=Int_implementations=6.verified.txt | 93 +++++++++ ...ngType=Long_implementations=0.verified.txt | 93 +++++++++ ...ngType=Long_implementations=2.verified.txt | 93 +++++++++ ...ngType=Long_implementations=4.verified.txt | 94 +++++++++ ...ngType=Long_implementations=6.verified.txt | 94 +++++++++ ...ransitNewId_implementations=0.verified.txt | 92 +++++++++ ...ransitNewId_implementations=2.verified.txt | 92 +++++++++ ...ransitNewId_implementations=4.verified.txt | 93 +++++++++ ...ransitNewId_implementations=6.verified.txt | 93 +++++++++ ...lableString_implementations=0.verified.txt | 108 ++++++++++ ...lableString_implementations=2.verified.txt | 108 ++++++++++ ...lableString_implementations=4.verified.txt | 118 +++++++++++ ...lableString_implementations=6.verified.txt | 118 +++++++++++ ...Type=String_implementations=0.verified.txt | 99 +++++++++ ...Type=String_implementations=2.verified.txt | 99 +++++++++ ...Type=String_implementations=4.verified.txt | 109 ++++++++++ ...Type=String_implementations=6.verified.txt | 109 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 134 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 134 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 135 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 135 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 134 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 134 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 135 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 135 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 137 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 137 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 138 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 138 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 142 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 142 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 143 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 143 +++++++++++++ ...lableString_implementations=0.verified.txt | 151 ++++++++++++++ ...lableString_implementations=2.verified.txt | 151 ++++++++++++++ ...lableString_implementations=4.verified.txt | 161 +++++++++++++++ ...lableString_implementations=6.verified.txt | 161 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 137 +++++++++++++ ...Type=String_implementations=2.verified.txt | 137 +++++++++++++ ...Type=String_implementations=4.verified.txt | 147 +++++++++++++ ...Type=String_implementations=6.verified.txt | 147 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 86 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 86 ++++++++ ...ingType=Int_implementations=0.verified.txt | 85 ++++++++ ...ingType=Int_implementations=2.verified.txt | 85 ++++++++ ...ingType=Int_implementations=4.verified.txt | 86 ++++++++ ...ingType=Int_implementations=6.verified.txt | 86 ++++++++ ...ngType=Long_implementations=0.verified.txt | 86 ++++++++ ...ngType=Long_implementations=2.verified.txt | 86 ++++++++ ...ngType=Long_implementations=4.verified.txt | 87 ++++++++ ...ngType=Long_implementations=6.verified.txt | 87 ++++++++ ...ransitNewId_implementations=0.verified.txt | 85 ++++++++ ...ransitNewId_implementations=2.verified.txt | 85 ++++++++ ...ransitNewId_implementations=4.verified.txt | 86 ++++++++ ...ransitNewId_implementations=6.verified.txt | 86 ++++++++ ...lableString_implementations=0.verified.txt | 102 +++++++++ ...lableString_implementations=2.verified.txt | 102 +++++++++ ...lableString_implementations=4.verified.txt | 112 ++++++++++ ...lableString_implementations=6.verified.txt | 112 ++++++++++ ...Type=String_implementations=0.verified.txt | 93 +++++++++ ...Type=String_implementations=2.verified.txt | 93 +++++++++ ...Type=String_implementations=4.verified.txt | 103 ++++++++++ ...Type=String_implementations=6.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 128 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 128 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 127 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 127 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 128 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 130 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 130 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 131 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 131 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 136 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 136 ++++++++++++ ...lableString_implementations=0.verified.txt | 145 +++++++++++++ ...lableString_implementations=2.verified.txt | 145 +++++++++++++ ...lableString_implementations=4.verified.txt | 155 ++++++++++++++ ...lableString_implementations=6.verified.txt | 155 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 131 ++++++++++++ ...Type=String_implementations=2.verified.txt | 131 ++++++++++++ ...Type=String_implementations=4.verified.txt | 141 +++++++++++++ ...Type=String_implementations=6.verified.txt | 141 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 107 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 107 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 106 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 106 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 107 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 108 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 108 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 106 ++++++++++ ...ransitNewId_implementations=2.verified.txt | 106 ++++++++++ ...ransitNewId_implementations=4.verified.txt | 107 ++++++++++ ...ransitNewId_implementations=6.verified.txt | 107 ++++++++++ ...lableString_implementations=0.verified.txt | 129 ++++++++++++ ...lableString_implementations=2.verified.txt | 129 ++++++++++++ ...lableString_implementations=4.verified.txt | 139 +++++++++++++ ...lableString_implementations=6.verified.txt | 139 +++++++++++++ ...Type=String_implementations=0.verified.txt | 113 ++++++++++ ...Type=String_implementations=2.verified.txt | 113 ++++++++++ ...Type=String_implementations=4.verified.txt | 123 +++++++++++ ...Type=String_implementations=6.verified.txt | 123 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 148 ++++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 148 ++++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 149 ++++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 149 ++++++++++++++ ...ingType=Int_implementations=0.verified.txt | 148 ++++++++++++++ ...ingType=Int_implementations=2.verified.txt | 148 ++++++++++++++ ...ingType=Int_implementations=4.verified.txt | 149 ++++++++++++++ ...ingType=Int_implementations=6.verified.txt | 149 ++++++++++++++ ...ngType=Long_implementations=0.verified.txt | 151 ++++++++++++++ ...ngType=Long_implementations=2.verified.txt | 151 ++++++++++++++ ...ngType=Long_implementations=4.verified.txt | 152 ++++++++++++++ ...ngType=Long_implementations=6.verified.txt | 152 ++++++++++++++ ...ransitNewId_implementations=0.verified.txt | 156 ++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 156 ++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 157 ++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 157 ++++++++++++++ ...lableString_implementations=0.verified.txt | 172 ++++++++++++++++ ...lableString_implementations=2.verified.txt | 172 ++++++++++++++++ ...lableString_implementations=4.verified.txt | 182 +++++++++++++++++ ...lableString_implementations=6.verified.txt | 182 +++++++++++++++++ ...Type=String_implementations=0.verified.txt | 151 ++++++++++++++ ...Type=String_implementations=2.verified.txt | 151 ++++++++++++++ ...Type=String_implementations=4.verified.txt | 161 +++++++++++++++ ...Type=String_implementations=6.verified.txt | 161 +++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 83 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 83 ++++++++ ...ingType=Int_implementations=0.verified.txt | 82 ++++++++ ...ingType=Int_implementations=2.verified.txt | 82 ++++++++ ...ingType=Int_implementations=4.verified.txt | 83 ++++++++ ...ingType=Int_implementations=6.verified.txt | 83 ++++++++ ...ngType=Long_implementations=0.verified.txt | 83 ++++++++ ...ngType=Long_implementations=2.verified.txt | 83 ++++++++ ...ngType=Long_implementations=4.verified.txt | 84 ++++++++ ...ngType=Long_implementations=6.verified.txt | 84 ++++++++ ...ransitNewId_implementations=0.verified.txt | 82 ++++++++ ...ransitNewId_implementations=2.verified.txt | 82 ++++++++ ...ransitNewId_implementations=4.verified.txt | 83 ++++++++ ...ransitNewId_implementations=6.verified.txt | 83 ++++++++ ...lableString_implementations=0.verified.txt | 92 +++++++++ ...lableString_implementations=2.verified.txt | 92 +++++++++ ...lableString_implementations=4.verified.txt | 102 +++++++++ ...lableString_implementations=6.verified.txt | 102 +++++++++ ...Type=String_implementations=0.verified.txt | 90 ++++++++ ...Type=String_implementations=2.verified.txt | 90 ++++++++ ...Type=String_implementations=4.verified.txt | 100 +++++++++ ...Type=String_implementations=6.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 125 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 125 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 124 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 124 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 125 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 125 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 128 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 133 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 133 ++++++++++++ ...lableString_implementations=0.verified.txt | 135 ++++++++++++ ...lableString_implementations=2.verified.txt | 135 ++++++++++++ ...lableString_implementations=4.verified.txt | 145 +++++++++++++ ...lableString_implementations=6.verified.txt | 145 +++++++++++++ ...Type=String_implementations=0.verified.txt | 128 ++++++++++++ ...Type=String_implementations=2.verified.txt | 128 ++++++++++++ ...Type=String_implementations=4.verified.txt | 138 +++++++++++++ ...Type=String_implementations=6.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 104 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 104 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 103 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 103 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 104 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 105 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 105 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=2.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=4.verified.txt | 104 ++++++++++ ...ransitNewId_implementations=6.verified.txt | 104 ++++++++++ ...lableString_implementations=0.verified.txt | 119 +++++++++++ ...lableString_implementations=2.verified.txt | 119 +++++++++++ ...lableString_implementations=4.verified.txt | 129 ++++++++++++ ...lableString_implementations=6.verified.txt | 129 ++++++++++++ ...Type=String_implementations=0.verified.txt | 110 ++++++++++ ...Type=String_implementations=2.verified.txt | 110 ++++++++++ ...Type=String_implementations=4.verified.txt | 120 +++++++++++ ...Type=String_implementations=6.verified.txt | 120 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 145 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 145 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 146 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 146 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 145 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 145 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 146 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 146 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 148 ++++++++++++++ ...ngType=Long_implementations=2.verified.txt | 148 ++++++++++++++ ...ngType=Long_implementations=4.verified.txt | 149 ++++++++++++++ ...ngType=Long_implementations=6.verified.txt | 149 ++++++++++++++ ...ransitNewId_implementations=0.verified.txt | 153 ++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 153 ++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 154 ++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 154 ++++++++++++++ ...lableString_implementations=0.verified.txt | 162 +++++++++++++++ ...lableString_implementations=2.verified.txt | 162 +++++++++++++++ ...lableString_implementations=4.verified.txt | 172 ++++++++++++++++ ...lableString_implementations=6.verified.txt | 172 ++++++++++++++++ ...Type=String_implementations=0.verified.txt | 148 ++++++++++++++ ...Type=String_implementations=2.verified.txt | 148 ++++++++++++++ ...Type=String_implementations=4.verified.txt | 158 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 158 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 96 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 96 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 97 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 97 +++++++++ ...ingType=Int_implementations=0.verified.txt | 96 +++++++++ ...ingType=Int_implementations=2.verified.txt | 96 +++++++++ ...ingType=Int_implementations=4.verified.txt | 97 +++++++++ ...ingType=Int_implementations=6.verified.txt | 97 +++++++++ ...ngType=Long_implementations=0.verified.txt | 97 +++++++++ ...ngType=Long_implementations=2.verified.txt | 97 +++++++++ ...ngType=Long_implementations=4.verified.txt | 98 +++++++++ ...ngType=Long_implementations=6.verified.txt | 98 +++++++++ ...ransitNewId_implementations=0.verified.txt | 96 +++++++++ ...ransitNewId_implementations=2.verified.txt | 96 +++++++++ ...ransitNewId_implementations=4.verified.txt | 97 +++++++++ ...ransitNewId_implementations=6.verified.txt | 97 +++++++++ ...lableString_implementations=0.verified.txt | 113 ++++++++++ ...lableString_implementations=2.verified.txt | 113 ++++++++++ ...lableString_implementations=4.verified.txt | 123 +++++++++++ ...lableString_implementations=6.verified.txt | 123 +++++++++++ ...Type=String_implementations=0.verified.txt | 104 ++++++++++ ...Type=String_implementations=2.verified.txt | 104 ++++++++++ ...Type=String_implementations=4.verified.txt | 114 +++++++++++ ...Type=String_implementations=6.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 139 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 139 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 138 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 138 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 139 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 139 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 141 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 141 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 142 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 142 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 146 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 146 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 147 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 147 +++++++++++++ ...lableString_implementations=0.verified.txt | 156 ++++++++++++++ ...lableString_implementations=2.verified.txt | 156 ++++++++++++++ ...lableString_implementations=4.verified.txt | 166 +++++++++++++++ ...lableString_implementations=6.verified.txt | 166 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 142 +++++++++++++ ...Type=String_implementations=2.verified.txt | 142 +++++++++++++ ...Type=String_implementations=4.verified.txt | 152 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 152 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 118 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 118 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 117 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 117 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 118 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 119 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 119 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 117 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 117 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 118 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 118 +++++++++++ ...lableString_implementations=0.verified.txt | 140 +++++++++++++ ...lableString_implementations=2.verified.txt | 140 +++++++++++++ ...lableString_implementations=4.verified.txt | 150 ++++++++++++++ ...lableString_implementations=6.verified.txt | 150 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 124 +++++++++++ ...Type=String_implementations=2.verified.txt | 124 +++++++++++ ...Type=String_implementations=4.verified.txt | 134 ++++++++++++ ...Type=String_implementations=6.verified.txt | 134 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 159 +++++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 159 +++++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 160 +++++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 160 +++++++++++++++ ...ingType=Int_implementations=0.verified.txt | 159 +++++++++++++++ ...ingType=Int_implementations=2.verified.txt | 159 +++++++++++++++ ...ingType=Int_implementations=4.verified.txt | 160 +++++++++++++++ ...ingType=Int_implementations=6.verified.txt | 160 +++++++++++++++ ...ngType=Long_implementations=0.verified.txt | 162 +++++++++++++++ ...ngType=Long_implementations=2.verified.txt | 162 +++++++++++++++ ...ngType=Long_implementations=4.verified.txt | 163 +++++++++++++++ ...ngType=Long_implementations=6.verified.txt | 163 +++++++++++++++ ...ransitNewId_implementations=0.verified.txt | 167 +++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 167 +++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 168 +++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 168 +++++++++++++++ ...lableString_implementations=0.verified.txt | 183 +++++++++++++++++ ...lableString_implementations=2.verified.txt | 183 +++++++++++++++++ ...lableString_implementations=4.verified.txt | 193 ++++++++++++++++++ ...lableString_implementations=6.verified.txt | 193 ++++++++++++++++++ ...Type=String_implementations=0.verified.txt | 162 +++++++++++++++ ...Type=String_implementations=2.verified.txt | 162 +++++++++++++++ ...Type=String_implementations=4.verified.txt | 172 ++++++++++++++++ ...Type=String_implementations=6.verified.txt | 172 ++++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 53 +++++ ...ngType=Guid_implementations=2.verified.txt | 53 +++++ ...ngType=Guid_implementations=4.verified.txt | 54 +++++ ...ngType=Guid_implementations=6.verified.txt | 54 +++++ ...ingType=Int_implementations=0.verified.txt | 52 +++++ ...ingType=Int_implementations=2.verified.txt | 52 +++++ ...ingType=Int_implementations=4.verified.txt | 53 +++++ ...ingType=Int_implementations=6.verified.txt | 53 +++++ ...ngType=Long_implementations=0.verified.txt | 52 +++++ ...ngType=Long_implementations=2.verified.txt | 52 +++++ ...ngType=Long_implementations=4.verified.txt | 53 +++++ ...ngType=Long_implementations=6.verified.txt | 53 +++++ ...ransitNewId_implementations=0.verified.txt | 53 +++++ ...ransitNewId_implementations=2.verified.txt | 53 +++++ ...ransitNewId_implementations=4.verified.txt | 54 +++++ ...ransitNewId_implementations=6.verified.txt | 54 +++++ ...lableString_implementations=0.verified.txt | 62 ++++++ ...lableString_implementations=2.verified.txt | 62 ++++++ ...lableString_implementations=4.verified.txt | 72 +++++++ ...lableString_implementations=6.verified.txt | 72 +++++++ ...Type=String_implementations=0.verified.txt | 62 ++++++ ...Type=String_implementations=2.verified.txt | 62 ++++++ ...Type=String_implementations=4.verified.txt | 72 +++++++ ...Type=String_implementations=6.verified.txt | 72 +++++++ ...ngType=Guid_implementations=0.verified.txt | 95 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 95 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 96 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 96 +++++++++ ...ingType=Int_implementations=0.verified.txt | 94 +++++++++ ...ingType=Int_implementations=2.verified.txt | 94 +++++++++ ...ingType=Int_implementations=4.verified.txt | 95 +++++++++ ...ingType=Int_implementations=6.verified.txt | 95 +++++++++ ...ngType=Long_implementations=0.verified.txt | 96 +++++++++ ...ngType=Long_implementations=2.verified.txt | 96 +++++++++ ...ngType=Long_implementations=4.verified.txt | 97 +++++++++ ...ngType=Long_implementations=6.verified.txt | 97 +++++++++ ...ransitNewId_implementations=0.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=2.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=4.verified.txt | 104 ++++++++++ ...ransitNewId_implementations=6.verified.txt | 104 ++++++++++ ...lableString_implementations=0.verified.txt | 105 ++++++++++ ...lableString_implementations=2.verified.txt | 105 ++++++++++ ...lableString_implementations=4.verified.txt | 115 +++++++++++ ...lableString_implementations=6.verified.txt | 115 +++++++++++ ...Type=String_implementations=0.verified.txt | 100 +++++++++ ...Type=String_implementations=2.verified.txt | 100 +++++++++ ...Type=String_implementations=4.verified.txt | 110 ++++++++++ ...Type=String_implementations=6.verified.txt | 110 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 74 +++++++ ...ngType=Guid_implementations=2.verified.txt | 74 +++++++ ...ngType=Guid_implementations=4.verified.txt | 75 +++++++ ...ngType=Guid_implementations=6.verified.txt | 75 +++++++ ...ingType=Int_implementations=0.verified.txt | 73 +++++++ ...ingType=Int_implementations=2.verified.txt | 73 +++++++ ...ingType=Int_implementations=4.verified.txt | 74 +++++++ ...ingType=Int_implementations=6.verified.txt | 74 +++++++ ...ngType=Long_implementations=0.verified.txt | 73 +++++++ ...ngType=Long_implementations=2.verified.txt | 73 +++++++ ...ngType=Long_implementations=4.verified.txt | 74 +++++++ ...ngType=Long_implementations=6.verified.txt | 74 +++++++ ...ransitNewId_implementations=0.verified.txt | 74 +++++++ ...ransitNewId_implementations=2.verified.txt | 74 +++++++ ...ransitNewId_implementations=4.verified.txt | 75 +++++++ ...ransitNewId_implementations=6.verified.txt | 75 +++++++ ...lableString_implementations=0.verified.txt | 89 ++++++++ ...lableString_implementations=2.verified.txt | 89 ++++++++ ...lableString_implementations=4.verified.txt | 99 +++++++++ ...lableString_implementations=6.verified.txt | 99 +++++++++ ...Type=String_implementations=0.verified.txt | 82 ++++++++ ...Type=String_implementations=2.verified.txt | 82 ++++++++ ...Type=String_implementations=4.verified.txt | 92 +++++++++ ...Type=String_implementations=6.verified.txt | 92 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 116 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 116 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 117 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 115 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 115 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 116 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 116 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 117 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 117 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 118 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 124 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 124 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 125 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 125 ++++++++++++ ...lableString_implementations=0.verified.txt | 132 ++++++++++++ ...lableString_implementations=2.verified.txt | 132 ++++++++++++ ...lableString_implementations=4.verified.txt | 142 +++++++++++++ ...lableString_implementations=6.verified.txt | 142 +++++++++++++ ...Type=String_implementations=0.verified.txt | 120 +++++++++++ ...Type=String_implementations=2.verified.txt | 120 +++++++++++ ...Type=String_implementations=4.verified.txt | 130 ++++++++++++ ...Type=String_implementations=6.verified.txt | 130 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 67 ++++++ ...ngType=Guid_implementations=2.verified.txt | 67 ++++++ ...ngType=Guid_implementations=4.verified.txt | 68 ++++++ ...ngType=Guid_implementations=6.verified.txt | 68 ++++++ ...ingType=Int_implementations=0.verified.txt | 66 ++++++ ...ingType=Int_implementations=2.verified.txt | 66 ++++++ ...ingType=Int_implementations=4.verified.txt | 67 ++++++ ...ingType=Int_implementations=6.verified.txt | 67 ++++++ ...ngType=Long_implementations=0.verified.txt | 66 ++++++ ...ngType=Long_implementations=2.verified.txt | 66 ++++++ ...ngType=Long_implementations=4.verified.txt | 67 ++++++ ...ngType=Long_implementations=6.verified.txt | 67 ++++++ ...ransitNewId_implementations=0.verified.txt | 67 ++++++ ...ransitNewId_implementations=2.verified.txt | 67 ++++++ ...ransitNewId_implementations=4.verified.txt | 68 ++++++ ...ransitNewId_implementations=6.verified.txt | 68 ++++++ ...lableString_implementations=0.verified.txt | 83 ++++++++ ...lableString_implementations=2.verified.txt | 83 ++++++++ ...lableString_implementations=4.verified.txt | 93 +++++++++ ...lableString_implementations=6.verified.txt | 93 +++++++++ ...Type=String_implementations=0.verified.txt | 76 +++++++ ...Type=String_implementations=2.verified.txt | 76 +++++++ ...Type=String_implementations=4.verified.txt | 86 ++++++++ ...Type=String_implementations=6.verified.txt | 86 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 109 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 109 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 110 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 110 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 108 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 108 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 109 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 109 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 110 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 110 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 111 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 111 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 117 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 117 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 118 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 118 +++++++++++ ...lableString_implementations=0.verified.txt | 126 ++++++++++++ ...lableString_implementations=2.verified.txt | 126 ++++++++++++ ...lableString_implementations=4.verified.txt | 136 ++++++++++++ ...lableString_implementations=6.verified.txt | 136 ++++++++++++ ...Type=String_implementations=0.verified.txt | 114 +++++++++++ ...Type=String_implementations=2.verified.txt | 114 +++++++++++ ...Type=String_implementations=4.verified.txt | 124 +++++++++++ ...Type=String_implementations=6.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 88 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 88 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 89 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 89 ++++++++ ...ingType=Int_implementations=0.verified.txt | 87 ++++++++ ...ingType=Int_implementations=2.verified.txt | 87 ++++++++ ...ingType=Int_implementations=4.verified.txt | 88 ++++++++ ...ingType=Int_implementations=6.verified.txt | 88 ++++++++ ...ngType=Long_implementations=0.verified.txt | 87 ++++++++ ...ngType=Long_implementations=2.verified.txt | 87 ++++++++ ...ngType=Long_implementations=4.verified.txt | 88 ++++++++ ...ngType=Long_implementations=6.verified.txt | 88 ++++++++ ...ransitNewId_implementations=0.verified.txt | 88 ++++++++ ...ransitNewId_implementations=2.verified.txt | 88 ++++++++ ...ransitNewId_implementations=4.verified.txt | 89 ++++++++ ...ransitNewId_implementations=6.verified.txt | 89 ++++++++ ...lableString_implementations=0.verified.txt | 110 ++++++++++ ...lableString_implementations=2.verified.txt | 110 ++++++++++ ...lableString_implementations=4.verified.txt | 120 +++++++++++ ...lableString_implementations=6.verified.txt | 120 +++++++++++ ...Type=String_implementations=0.verified.txt | 96 +++++++++ ...Type=String_implementations=2.verified.txt | 96 +++++++++ ...Type=String_implementations=4.verified.txt | 106 ++++++++++ ...Type=String_implementations=6.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 130 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 130 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 131 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 131 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 129 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 129 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 130 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 130 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 131 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 131 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 132 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 138 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 138 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 139 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 139 +++++++++++++ ...lableString_implementations=0.verified.txt | 153 ++++++++++++++ ...lableString_implementations=2.verified.txt | 153 ++++++++++++++ ...lableString_implementations=4.verified.txt | 163 +++++++++++++++ ...lableString_implementations=6.verified.txt | 163 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 134 ++++++++++++ ...Type=String_implementations=2.verified.txt | 134 ++++++++++++ ...Type=String_implementations=4.verified.txt | 144 +++++++++++++ ...Type=String_implementations=6.verified.txt | 144 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 64 ++++++ ...ngType=Guid_implementations=2.verified.txt | 64 ++++++ ...ngType=Guid_implementations=4.verified.txt | 65 ++++++ ...ngType=Guid_implementations=6.verified.txt | 65 ++++++ ...ingType=Int_implementations=0.verified.txt | 63 ++++++ ...ingType=Int_implementations=2.verified.txt | 63 ++++++ ...ingType=Int_implementations=4.verified.txt | 64 ++++++ ...ingType=Int_implementations=6.verified.txt | 64 ++++++ ...ngType=Long_implementations=0.verified.txt | 63 ++++++ ...ngType=Long_implementations=2.verified.txt | 63 ++++++ ...ngType=Long_implementations=4.verified.txt | 64 ++++++ ...ngType=Long_implementations=6.verified.txt | 64 ++++++ ...ransitNewId_implementations=0.verified.txt | 64 ++++++ ...ransitNewId_implementations=2.verified.txt | 64 ++++++ ...ransitNewId_implementations=4.verified.txt | 65 ++++++ ...ransitNewId_implementations=6.verified.txt | 65 ++++++ ...lableString_implementations=0.verified.txt | 73 +++++++ ...lableString_implementations=2.verified.txt | 73 +++++++ ...lableString_implementations=4.verified.txt | 83 ++++++++ ...lableString_implementations=6.verified.txt | 83 ++++++++ ...Type=String_implementations=0.verified.txt | 73 +++++++ ...Type=String_implementations=2.verified.txt | 73 +++++++ ...Type=String_implementations=4.verified.txt | 83 ++++++++ ...Type=String_implementations=6.verified.txt | 83 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 107 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 107 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 105 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 105 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 106 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 106 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 108 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 108 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 115 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 115 +++++++++++ ...lableString_implementations=0.verified.txt | 116 +++++++++++ ...lableString_implementations=2.verified.txt | 116 +++++++++++ ...lableString_implementations=4.verified.txt | 126 ++++++++++++ ...lableString_implementations=6.verified.txt | 126 ++++++++++++ ...Type=String_implementations=0.verified.txt | 111 ++++++++++ ...Type=String_implementations=2.verified.txt | 111 ++++++++++ ...Type=String_implementations=4.verified.txt | 121 +++++++++++ ...Type=String_implementations=6.verified.txt | 121 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 86 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 86 ++++++++ ...ingType=Int_implementations=0.verified.txt | 84 ++++++++ ...ingType=Int_implementations=2.verified.txt | 84 ++++++++ ...ingType=Int_implementations=4.verified.txt | 85 ++++++++ ...ingType=Int_implementations=6.verified.txt | 85 ++++++++ ...ngType=Long_implementations=0.verified.txt | 84 ++++++++ ...ngType=Long_implementations=2.verified.txt | 84 ++++++++ ...ngType=Long_implementations=4.verified.txt | 85 ++++++++ ...ngType=Long_implementations=6.verified.txt | 85 ++++++++ ...ransitNewId_implementations=0.verified.txt | 85 ++++++++ ...ransitNewId_implementations=2.verified.txt | 85 ++++++++ ...ransitNewId_implementations=4.verified.txt | 86 ++++++++ ...ransitNewId_implementations=6.verified.txt | 86 ++++++++ ...lableString_implementations=0.verified.txt | 100 +++++++++ ...lableString_implementations=2.verified.txt | 100 +++++++++ ...lableString_implementations=4.verified.txt | 110 ++++++++++ ...lableString_implementations=6.verified.txt | 110 ++++++++++ ...Type=String_implementations=0.verified.txt | 93 +++++++++ ...Type=String_implementations=2.verified.txt | 93 +++++++++ ...Type=String_implementations=4.verified.txt | 103 ++++++++++ ...Type=String_implementations=6.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 128 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 128 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 126 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 126 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 127 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 129 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 129 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 136 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 136 ++++++++++++ ...lableString_implementations=0.verified.txt | 143 +++++++++++++ ...lableString_implementations=2.verified.txt | 143 +++++++++++++ ...lableString_implementations=4.verified.txt | 153 ++++++++++++++ ...lableString_implementations=6.verified.txt | 153 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 131 ++++++++++++ ...Type=String_implementations=2.verified.txt | 131 ++++++++++++ ...Type=String_implementations=4.verified.txt | 141 +++++++++++++ ...Type=String_implementations=6.verified.txt | 141 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 78 +++++++ ...ngType=Guid_implementations=2.verified.txt | 78 +++++++ ...ngType=Guid_implementations=4.verified.txt | 79 +++++++ ...ngType=Guid_implementations=6.verified.txt | 79 +++++++ ...ingType=Int_implementations=0.verified.txt | 77 +++++++ ...ingType=Int_implementations=2.verified.txt | 77 +++++++ ...ingType=Int_implementations=4.verified.txt | 78 +++++++ ...ingType=Int_implementations=6.verified.txt | 78 +++++++ ...ngType=Long_implementations=0.verified.txt | 77 +++++++ ...ngType=Long_implementations=2.verified.txt | 77 +++++++ ...ngType=Long_implementations=4.verified.txt | 78 +++++++ ...ngType=Long_implementations=6.verified.txt | 78 +++++++ ...ransitNewId_implementations=0.verified.txt | 78 +++++++ ...ransitNewId_implementations=2.verified.txt | 78 +++++++ ...ransitNewId_implementations=4.verified.txt | 79 +++++++ ...ransitNewId_implementations=6.verified.txt | 79 +++++++ ...lableString_implementations=0.verified.txt | 94 +++++++++ ...lableString_implementations=2.verified.txt | 94 +++++++++ ...lableString_implementations=4.verified.txt | 104 ++++++++++ ...lableString_implementations=6.verified.txt | 104 ++++++++++ ...Type=String_implementations=0.verified.txt | 87 ++++++++ ...Type=String_implementations=2.verified.txt | 87 ++++++++ ...Type=String_implementations=4.verified.txt | 97 +++++++++ ...Type=String_implementations=6.verified.txt | 97 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 120 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 120 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 121 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 121 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 119 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 119 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 120 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 120 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 121 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 121 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 122 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 122 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 128 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 128 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 129 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 129 ++++++++++++ ...lableString_implementations=0.verified.txt | 137 +++++++++++++ ...lableString_implementations=2.verified.txt | 137 +++++++++++++ ...lableString_implementations=4.verified.txt | 147 +++++++++++++ ...lableString_implementations=6.verified.txt | 147 +++++++++++++ ...Type=String_implementations=0.verified.txt | 125 ++++++++++++ ...Type=String_implementations=2.verified.txt | 125 ++++++++++++ ...Type=String_implementations=4.verified.txt | 135 ++++++++++++ ...Type=String_implementations=6.verified.txt | 135 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 99 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 99 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 100 +++++++++ ...ingType=Int_implementations=0.verified.txt | 98 +++++++++ ...ingType=Int_implementations=2.verified.txt | 98 +++++++++ ...ingType=Int_implementations=4.verified.txt | 99 +++++++++ ...ingType=Int_implementations=6.verified.txt | 99 +++++++++ ...ngType=Long_implementations=0.verified.txt | 98 +++++++++ ...ngType=Long_implementations=2.verified.txt | 98 +++++++++ ...ngType=Long_implementations=4.verified.txt | 99 +++++++++ ...ngType=Long_implementations=6.verified.txt | 99 +++++++++ ...ransitNewId_implementations=0.verified.txt | 99 +++++++++ ...ransitNewId_implementations=2.verified.txt | 99 +++++++++ ...ransitNewId_implementations=4.verified.txt | 100 +++++++++ ...ransitNewId_implementations=6.verified.txt | 100 +++++++++ ...lableString_implementations=0.verified.txt | 121 +++++++++++ ...lableString_implementations=2.verified.txt | 121 +++++++++++ ...lableString_implementations=4.verified.txt | 131 ++++++++++++ ...lableString_implementations=6.verified.txt | 131 ++++++++++++ ...Type=String_implementations=0.verified.txt | 107 ++++++++++ ...Type=String_implementations=2.verified.txt | 107 ++++++++++ ...Type=String_implementations=4.verified.txt | 117 +++++++++++ ...Type=String_implementations=6.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 141 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 141 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 142 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 142 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 140 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 140 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 141 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 141 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 142 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 142 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 143 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 143 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 149 ++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 149 ++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 150 ++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 150 ++++++++++++++ ...lableString_implementations=0.verified.txt | 164 +++++++++++++++ ...lableString_implementations=2.verified.txt | 164 +++++++++++++++ ...lableString_implementations=4.verified.txt | 174 ++++++++++++++++ ...lableString_implementations=6.verified.txt | 174 ++++++++++++++++ ...Type=String_implementations=0.verified.txt | 145 +++++++++++++ ...Type=String_implementations=2.verified.txt | 145 +++++++++++++ ...Type=String_implementations=4.verified.txt | 155 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 155 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 71 +++++++ ...ngType=Guid_implementations=2.verified.txt | 71 +++++++ ...ngType=Guid_implementations=4.verified.txt | 72 +++++++ ...ngType=Guid_implementations=6.verified.txt | 72 +++++++ ...ingType=Int_implementations=0.verified.txt | 71 +++++++ ...ingType=Int_implementations=2.verified.txt | 71 +++++++ ...ingType=Int_implementations=4.verified.txt | 72 +++++++ ...ingType=Int_implementations=6.verified.txt | 72 +++++++ ...ngType=Long_implementations=0.verified.txt | 72 +++++++ ...ngType=Long_implementations=2.verified.txt | 72 +++++++ ...ngType=Long_implementations=4.verified.txt | 73 +++++++ ...ngType=Long_implementations=6.verified.txt | 73 +++++++ ...ransitNewId_implementations=0.verified.txt | 71 +++++++ ...ransitNewId_implementations=2.verified.txt | 71 +++++++ ...ransitNewId_implementations=4.verified.txt | 72 +++++++ ...ransitNewId_implementations=6.verified.txt | 72 +++++++ ...lableString_implementations=0.verified.txt | 81 ++++++++ ...lableString_implementations=2.verified.txt | 81 ++++++++ ...lableString_implementations=4.verified.txt | 91 +++++++++ ...lableString_implementations=6.verified.txt | 91 +++++++++ ...Type=String_implementations=0.verified.txt | 79 +++++++ ...Type=String_implementations=2.verified.txt | 79 +++++++ ...Type=String_implementations=4.verified.txt | 89 ++++++++ ...Type=String_implementations=6.verified.txt | 89 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 113 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 113 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 114 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 113 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 113 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 114 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 114 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 116 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 116 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 117 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 117 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 121 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 121 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 122 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 122 +++++++++++ ...lableString_implementations=0.verified.txt | 124 +++++++++++ ...lableString_implementations=2.verified.txt | 124 +++++++++++ ...lableString_implementations=4.verified.txt | 134 ++++++++++++ ...lableString_implementations=6.verified.txt | 134 ++++++++++++ ...Type=String_implementations=0.verified.txt | 117 +++++++++++ ...Type=String_implementations=2.verified.txt | 117 +++++++++++ ...Type=String_implementations=4.verified.txt | 127 ++++++++++++ ...Type=String_implementations=6.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 89 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 89 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 90 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 90 ++++++++ ...ingType=Int_implementations=0.verified.txt | 89 ++++++++ ...ingType=Int_implementations=2.verified.txt | 89 ++++++++ ...ingType=Int_implementations=4.verified.txt | 90 ++++++++ ...ingType=Int_implementations=6.verified.txt | 90 ++++++++ ...ngType=Long_implementations=0.verified.txt | 90 ++++++++ ...ngType=Long_implementations=2.verified.txt | 90 ++++++++ ...ngType=Long_implementations=4.verified.txt | 91 +++++++++ ...ngType=Long_implementations=6.verified.txt | 91 +++++++++ ...ransitNewId_implementations=0.verified.txt | 89 ++++++++ ...ransitNewId_implementations=2.verified.txt | 89 ++++++++ ...ransitNewId_implementations=4.verified.txt | 90 ++++++++ ...ransitNewId_implementations=6.verified.txt | 90 ++++++++ ...lableString_implementations=0.verified.txt | 105 ++++++++++ ...lableString_implementations=2.verified.txt | 105 ++++++++++ ...lableString_implementations=4.verified.txt | 115 +++++++++++ ...lableString_implementations=6.verified.txt | 115 +++++++++++ ...Type=String_implementations=0.verified.txt | 96 +++++++++ ...Type=String_implementations=2.verified.txt | 96 +++++++++ ...Type=String_implementations=4.verified.txt | 106 ++++++++++ ...Type=String_implementations=6.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 131 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 131 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 132 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 132 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 131 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 131 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 132 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 132 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 134 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 134 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 135 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 139 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 139 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 140 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 140 +++++++++++++ ...lableString_implementations=0.verified.txt | 148 ++++++++++++++ ...lableString_implementations=2.verified.txt | 148 ++++++++++++++ ...lableString_implementations=4.verified.txt | 158 ++++++++++++++ ...lableString_implementations=6.verified.txt | 158 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 134 ++++++++++++ ...Type=String_implementations=2.verified.txt | 134 ++++++++++++ ...Type=String_implementations=4.verified.txt | 144 +++++++++++++ ...Type=String_implementations=6.verified.txt | 144 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 83 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 83 ++++++++ ...ingType=Int_implementations=0.verified.txt | 82 ++++++++ ...ingType=Int_implementations=2.verified.txt | 82 ++++++++ ...ingType=Int_implementations=4.verified.txt | 83 ++++++++ ...ingType=Int_implementations=6.verified.txt | 83 ++++++++ ...ngType=Long_implementations=0.verified.txt | 83 ++++++++ ...ngType=Long_implementations=2.verified.txt | 83 ++++++++ ...ngType=Long_implementations=4.verified.txt | 84 ++++++++ ...ngType=Long_implementations=6.verified.txt | 84 ++++++++ ...ransitNewId_implementations=0.verified.txt | 82 ++++++++ ...ransitNewId_implementations=2.verified.txt | 82 ++++++++ ...ransitNewId_implementations=4.verified.txt | 83 ++++++++ ...ransitNewId_implementations=6.verified.txt | 83 ++++++++ ...lableString_implementations=0.verified.txt | 99 +++++++++ ...lableString_implementations=2.verified.txt | 99 +++++++++ ...lableString_implementations=4.verified.txt | 109 ++++++++++ ...lableString_implementations=6.verified.txt | 109 ++++++++++ ...Type=String_implementations=0.verified.txt | 90 ++++++++ ...Type=String_implementations=2.verified.txt | 90 ++++++++ ...Type=String_implementations=4.verified.txt | 100 +++++++++ ...Type=String_implementations=6.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 125 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 125 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 124 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 124 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 125 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 125 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 128 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 133 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 133 ++++++++++++ ...lableString_implementations=0.verified.txt | 142 +++++++++++++ ...lableString_implementations=2.verified.txt | 142 +++++++++++++ ...lableString_implementations=4.verified.txt | 152 ++++++++++++++ ...lableString_implementations=6.verified.txt | 152 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 128 ++++++++++++ ...Type=String_implementations=2.verified.txt | 128 ++++++++++++ ...Type=String_implementations=4.verified.txt | 138 +++++++++++++ ...Type=String_implementations=6.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 104 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 104 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 103 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 103 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 104 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 105 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 105 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=2.verified.txt | 103 ++++++++++ ...ransitNewId_implementations=4.verified.txt | 104 ++++++++++ ...ransitNewId_implementations=6.verified.txt | 104 ++++++++++ ...lableString_implementations=0.verified.txt | 126 ++++++++++++ ...lableString_implementations=2.verified.txt | 126 ++++++++++++ ...lableString_implementations=4.verified.txt | 136 ++++++++++++ ...lableString_implementations=6.verified.txt | 136 ++++++++++++ ...Type=String_implementations=0.verified.txt | 110 ++++++++++ ...Type=String_implementations=2.verified.txt | 110 ++++++++++ ...Type=String_implementations=4.verified.txt | 120 +++++++++++ ...Type=String_implementations=6.verified.txt | 120 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 145 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 145 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 146 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 146 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 145 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 145 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 146 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 146 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 148 ++++++++++++++ ...ngType=Long_implementations=2.verified.txt | 148 ++++++++++++++ ...ngType=Long_implementations=4.verified.txt | 149 ++++++++++++++ ...ngType=Long_implementations=6.verified.txt | 149 ++++++++++++++ ...ransitNewId_implementations=0.verified.txt | 153 ++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 153 ++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 154 ++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 154 ++++++++++++++ ...lableString_implementations=0.verified.txt | 169 +++++++++++++++ ...lableString_implementations=2.verified.txt | 169 +++++++++++++++ ...lableString_implementations=4.verified.txt | 179 ++++++++++++++++ ...lableString_implementations=6.verified.txt | 179 ++++++++++++++++ ...Type=String_implementations=0.verified.txt | 148 ++++++++++++++ ...Type=String_implementations=2.verified.txt | 148 ++++++++++++++ ...Type=String_implementations=4.verified.txt | 158 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 158 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 79 +++++++ ...ngType=Guid_implementations=2.verified.txt | 79 +++++++ ...ngType=Guid_implementations=4.verified.txt | 80 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 80 ++++++++ ...ingType=Int_implementations=0.verified.txt | 79 +++++++ ...ingType=Int_implementations=2.verified.txt | 79 +++++++ ...ingType=Int_implementations=4.verified.txt | 80 ++++++++ ...ingType=Int_implementations=6.verified.txt | 80 ++++++++ ...ngType=Long_implementations=0.verified.txt | 80 ++++++++ ...ngType=Long_implementations=2.verified.txt | 80 ++++++++ ...ngType=Long_implementations=4.verified.txt | 81 ++++++++ ...ngType=Long_implementations=6.verified.txt | 81 ++++++++ ...ransitNewId_implementations=0.verified.txt | 79 +++++++ ...ransitNewId_implementations=2.verified.txt | 79 +++++++ ...ransitNewId_implementations=4.verified.txt | 80 ++++++++ ...ransitNewId_implementations=6.verified.txt | 80 ++++++++ ...lableString_implementations=0.verified.txt | 89 ++++++++ ...lableString_implementations=2.verified.txt | 89 ++++++++ ...lableString_implementations=4.verified.txt | 99 +++++++++ ...lableString_implementations=6.verified.txt | 99 +++++++++ ...Type=String_implementations=0.verified.txt | 87 ++++++++ ...Type=String_implementations=2.verified.txt | 87 ++++++++ ...Type=String_implementations=4.verified.txt | 97 +++++++++ ...Type=String_implementations=6.verified.txt | 97 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 121 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 121 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 122 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 122 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 121 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 121 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 122 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 122 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 124 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 124 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 125 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 125 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 129 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 129 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 130 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 130 ++++++++++++ ...lableString_implementations=0.verified.txt | 132 ++++++++++++ ...lableString_implementations=2.verified.txt | 132 ++++++++++++ ...lableString_implementations=4.verified.txt | 142 +++++++++++++ ...lableString_implementations=6.verified.txt | 142 +++++++++++++ ...Type=String_implementations=0.verified.txt | 125 ++++++++++++ ...Type=String_implementations=2.verified.txt | 125 ++++++++++++ ...Type=String_implementations=4.verified.txt | 135 ++++++++++++ ...Type=String_implementations=6.verified.txt | 135 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 101 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 101 +++++++++ ...ingType=Int_implementations=0.verified.txt | 100 +++++++++ ...ingType=Int_implementations=2.verified.txt | 100 +++++++++ ...ingType=Int_implementations=4.verified.txt | 101 +++++++++ ...ingType=Int_implementations=6.verified.txt | 101 +++++++++ ...ngType=Long_implementations=0.verified.txt | 101 +++++++++ ...ngType=Long_implementations=2.verified.txt | 101 +++++++++ ...ngType=Long_implementations=4.verified.txt | 102 +++++++++ ...ngType=Long_implementations=6.verified.txt | 102 +++++++++ ...ransitNewId_implementations=0.verified.txt | 100 +++++++++ ...ransitNewId_implementations=2.verified.txt | 100 +++++++++ ...ransitNewId_implementations=4.verified.txt | 101 +++++++++ ...ransitNewId_implementations=6.verified.txt | 101 +++++++++ ...lableString_implementations=0.verified.txt | 116 +++++++++++ ...lableString_implementations=2.verified.txt | 116 +++++++++++ ...lableString_implementations=4.verified.txt | 126 ++++++++++++ ...lableString_implementations=6.verified.txt | 126 ++++++++++++ ...Type=String_implementations=0.verified.txt | 107 ++++++++++ ...Type=String_implementations=2.verified.txt | 107 ++++++++++ ...Type=String_implementations=4.verified.txt | 117 +++++++++++ ...Type=String_implementations=6.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 142 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 142 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 143 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 143 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 142 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 142 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 143 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 143 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 145 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 145 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 146 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 146 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 150 ++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 150 ++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 151 ++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 151 ++++++++++++++ ...lableString_implementations=0.verified.txt | 159 +++++++++++++++ ...lableString_implementations=2.verified.txt | 159 +++++++++++++++ ...lableString_implementations=4.verified.txt | 169 +++++++++++++++ ...lableString_implementations=6.verified.txt | 169 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 145 +++++++++++++ ...Type=String_implementations=2.verified.txt | 145 +++++++++++++ ...Type=String_implementations=4.verified.txt | 155 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 155 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 93 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 93 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 94 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 94 +++++++++ ...ingType=Int_implementations=0.verified.txt | 93 +++++++++ ...ingType=Int_implementations=2.verified.txt | 93 +++++++++ ...ingType=Int_implementations=4.verified.txt | 94 +++++++++ ...ingType=Int_implementations=6.verified.txt | 94 +++++++++ ...ngType=Long_implementations=0.verified.txt | 94 +++++++++ ...ngType=Long_implementations=2.verified.txt | 94 +++++++++ ...ngType=Long_implementations=4.verified.txt | 95 +++++++++ ...ngType=Long_implementations=6.verified.txt | 95 +++++++++ ...ransitNewId_implementations=0.verified.txt | 93 +++++++++ ...ransitNewId_implementations=2.verified.txt | 93 +++++++++ ...ransitNewId_implementations=4.verified.txt | 94 +++++++++ ...ransitNewId_implementations=6.verified.txt | 94 +++++++++ ...lableString_implementations=0.verified.txt | 110 ++++++++++ ...lableString_implementations=2.verified.txt | 110 ++++++++++ ...lableString_implementations=4.verified.txt | 120 +++++++++++ ...lableString_implementations=6.verified.txt | 120 +++++++++++ ...Type=String_implementations=0.verified.txt | 101 +++++++++ ...Type=String_implementations=2.verified.txt | 101 +++++++++ ...Type=String_implementations=4.verified.txt | 111 ++++++++++ ...Type=String_implementations=6.verified.txt | 111 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 135 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 135 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 136 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 136 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 135 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 135 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 136 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 136 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 138 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 138 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 139 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 139 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 143 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 143 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 144 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 144 +++++++++++++ ...lableString_implementations=0.verified.txt | 153 ++++++++++++++ ...lableString_implementations=2.verified.txt | 153 ++++++++++++++ ...lableString_implementations=4.verified.txt | 163 +++++++++++++++ ...lableString_implementations=6.verified.txt | 163 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 139 +++++++++++++ ...Type=String_implementations=2.verified.txt | 139 +++++++++++++ ...Type=String_implementations=4.verified.txt | 149 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 149 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 115 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 115 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 114 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 114 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 115 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 115 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 115 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 115 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 116 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 116 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 115 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 115 +++++++++++ ...lableString_implementations=0.verified.txt | 137 +++++++++++++ ...lableString_implementations=2.verified.txt | 137 +++++++++++++ ...lableString_implementations=4.verified.txt | 147 +++++++++++++ ...lableString_implementations=6.verified.txt | 147 +++++++++++++ ...Type=String_implementations=0.verified.txt | 121 +++++++++++ ...Type=String_implementations=2.verified.txt | 121 +++++++++++ ...Type=String_implementations=4.verified.txt | 131 ++++++++++++ ...Type=String_implementations=6.verified.txt | 131 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 156 ++++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 156 ++++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 157 ++++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 157 ++++++++++++++ ...ingType=Int_implementations=0.verified.txt | 156 ++++++++++++++ ...ingType=Int_implementations=2.verified.txt | 156 ++++++++++++++ ...ingType=Int_implementations=4.verified.txt | 157 ++++++++++++++ ...ingType=Int_implementations=6.verified.txt | 157 ++++++++++++++ ...ngType=Long_implementations=0.verified.txt | 159 +++++++++++++++ ...ngType=Long_implementations=2.verified.txt | 159 +++++++++++++++ ...ngType=Long_implementations=4.verified.txt | 160 +++++++++++++++ ...ngType=Long_implementations=6.verified.txt | 160 +++++++++++++++ ...ransitNewId_implementations=0.verified.txt | 164 +++++++++++++++ ...ransitNewId_implementations=2.verified.txt | 164 +++++++++++++++ ...ransitNewId_implementations=4.verified.txt | 165 +++++++++++++++ ...ransitNewId_implementations=6.verified.txt | 165 +++++++++++++++ ...lableString_implementations=0.verified.txt | 180 ++++++++++++++++ ...lableString_implementations=2.verified.txt | 180 ++++++++++++++++ ...lableString_implementations=4.verified.txt | 190 +++++++++++++++++ ...lableString_implementations=6.verified.txt | 190 +++++++++++++++++ ...Type=String_implementations=0.verified.txt | 159 +++++++++++++++ ...Type=String_implementations=2.verified.txt | 159 +++++++++++++++ ...Type=String_implementations=4.verified.txt | 169 +++++++++++++++ ...Type=String_implementations=6.verified.txt | 169 +++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 50 +++++ ...ngType=Guid_implementations=2.verified.txt | 50 +++++ ...ngType=Guid_implementations=4.verified.txt | 51 +++++ ...ngType=Guid_implementations=6.verified.txt | 51 +++++ ...ingType=Int_implementations=0.verified.txt | 49 +++++ ...ingType=Int_implementations=2.verified.txt | 49 +++++ ...ingType=Int_implementations=4.verified.txt | 50 +++++ ...ingType=Int_implementations=6.verified.txt | 50 +++++ ...ngType=Long_implementations=0.verified.txt | 49 +++++ ...ngType=Long_implementations=2.verified.txt | 49 +++++ ...ngType=Long_implementations=4.verified.txt | 50 +++++ ...ngType=Long_implementations=6.verified.txt | 50 +++++ ...ransitNewId_implementations=0.verified.txt | 50 +++++ ...ransitNewId_implementations=2.verified.txt | 50 +++++ ...ransitNewId_implementations=4.verified.txt | 51 +++++ ...ransitNewId_implementations=6.verified.txt | 51 +++++ ...lableString_implementations=0.verified.txt | 59 ++++++ ...lableString_implementations=2.verified.txt | 59 ++++++ ...lableString_implementations=4.verified.txt | 69 +++++++ ...lableString_implementations=6.verified.txt | 69 +++++++ ...Type=String_implementations=0.verified.txt | 59 ++++++ ...Type=String_implementations=2.verified.txt | 59 ++++++ ...Type=String_implementations=4.verified.txt | 69 +++++++ ...Type=String_implementations=6.verified.txt | 69 +++++++ ...ngType=Guid_implementations=0.verified.txt | 92 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 92 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 93 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 93 +++++++++ ...ingType=Int_implementations=0.verified.txt | 91 +++++++++ ...ingType=Int_implementations=2.verified.txt | 91 +++++++++ ...ingType=Int_implementations=4.verified.txt | 92 +++++++++ ...ingType=Int_implementations=6.verified.txt | 92 +++++++++ ...ngType=Long_implementations=0.verified.txt | 93 +++++++++ ...ngType=Long_implementations=2.verified.txt | 93 +++++++++ ...ngType=Long_implementations=4.verified.txt | 94 +++++++++ ...ngType=Long_implementations=6.verified.txt | 94 +++++++++ ...ransitNewId_implementations=0.verified.txt | 100 +++++++++ ...ransitNewId_implementations=2.verified.txt | 100 +++++++++ ...ransitNewId_implementations=4.verified.txt | 101 +++++++++ ...ransitNewId_implementations=6.verified.txt | 101 +++++++++ ...lableString_implementations=0.verified.txt | 102 +++++++++ ...lableString_implementations=2.verified.txt | 102 +++++++++ ...lableString_implementations=4.verified.txt | 112 ++++++++++ ...lableString_implementations=6.verified.txt | 112 ++++++++++ ...Type=String_implementations=0.verified.txt | 97 +++++++++ ...Type=String_implementations=2.verified.txt | 97 +++++++++ ...Type=String_implementations=4.verified.txt | 107 ++++++++++ ...Type=String_implementations=6.verified.txt | 107 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 71 +++++++ ...ngType=Guid_implementations=2.verified.txt | 71 +++++++ ...ngType=Guid_implementations=4.verified.txt | 72 +++++++ ...ngType=Guid_implementations=6.verified.txt | 72 +++++++ ...ingType=Int_implementations=0.verified.txt | 70 +++++++ ...ingType=Int_implementations=2.verified.txt | 70 +++++++ ...ingType=Int_implementations=4.verified.txt | 71 +++++++ ...ingType=Int_implementations=6.verified.txt | 71 +++++++ ...ngType=Long_implementations=0.verified.txt | 70 +++++++ ...ngType=Long_implementations=2.verified.txt | 70 +++++++ ...ngType=Long_implementations=4.verified.txt | 71 +++++++ ...ngType=Long_implementations=6.verified.txt | 71 +++++++ ...ransitNewId_implementations=0.verified.txt | 71 +++++++ ...ransitNewId_implementations=2.verified.txt | 71 +++++++ ...ransitNewId_implementations=4.verified.txt | 72 +++++++ ...ransitNewId_implementations=6.verified.txt | 72 +++++++ ...lableString_implementations=0.verified.txt | 86 ++++++++ ...lableString_implementations=2.verified.txt | 86 ++++++++ ...lableString_implementations=4.verified.txt | 96 +++++++++ ...lableString_implementations=6.verified.txt | 96 +++++++++ ...Type=String_implementations=0.verified.txt | 79 +++++++ ...Type=String_implementations=2.verified.txt | 79 +++++++ ...Type=String_implementations=4.verified.txt | 89 ++++++++ ...Type=String_implementations=6.verified.txt | 89 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 113 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 113 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 114 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 112 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 112 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 113 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 113 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 114 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 114 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 115 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 115 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 121 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 121 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 122 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 122 +++++++++++ ...lableString_implementations=0.verified.txt | 129 ++++++++++++ ...lableString_implementations=2.verified.txt | 129 ++++++++++++ ...lableString_implementations=4.verified.txt | 139 +++++++++++++ ...lableString_implementations=6.verified.txt | 139 +++++++++++++ ...Type=String_implementations=0.verified.txt | 117 +++++++++++ ...Type=String_implementations=2.verified.txt | 117 +++++++++++ ...Type=String_implementations=4.verified.txt | 127 ++++++++++++ ...Type=String_implementations=6.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 64 ++++++ ...ngType=Guid_implementations=2.verified.txt | 64 ++++++ ...ngType=Guid_implementations=4.verified.txt | 65 ++++++ ...ngType=Guid_implementations=6.verified.txt | 65 ++++++ ...ingType=Int_implementations=0.verified.txt | 63 ++++++ ...ingType=Int_implementations=2.verified.txt | 63 ++++++ ...ingType=Int_implementations=4.verified.txt | 64 ++++++ ...ingType=Int_implementations=6.verified.txt | 64 ++++++ ...ngType=Long_implementations=0.verified.txt | 63 ++++++ ...ngType=Long_implementations=2.verified.txt | 63 ++++++ ...ngType=Long_implementations=4.verified.txt | 64 ++++++ ...ngType=Long_implementations=6.verified.txt | 64 ++++++ ...ransitNewId_implementations=0.verified.txt | 64 ++++++ ...ransitNewId_implementations=2.verified.txt | 64 ++++++ ...ransitNewId_implementations=4.verified.txt | 65 ++++++ ...ransitNewId_implementations=6.verified.txt | 65 ++++++ ...lableString_implementations=0.verified.txt | 80 ++++++++ ...lableString_implementations=2.verified.txt | 80 ++++++++ ...lableString_implementations=4.verified.txt | 90 ++++++++ ...lableString_implementations=6.verified.txt | 90 ++++++++ ...Type=String_implementations=0.verified.txt | 73 +++++++ ...Type=String_implementations=2.verified.txt | 73 +++++++ ...Type=String_implementations=4.verified.txt | 83 ++++++++ ...Type=String_implementations=6.verified.txt | 83 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 106 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 107 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 107 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 105 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 105 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 106 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 106 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 107 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 108 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 108 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 115 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 115 +++++++++++ ...lableString_implementations=0.verified.txt | 123 +++++++++++ ...lableString_implementations=2.verified.txt | 123 +++++++++++ ...lableString_implementations=4.verified.txt | 133 ++++++++++++ ...lableString_implementations=6.verified.txt | 133 ++++++++++++ ...Type=String_implementations=0.verified.txt | 111 ++++++++++ ...Type=String_implementations=2.verified.txt | 111 ++++++++++ ...Type=String_implementations=4.verified.txt | 121 +++++++++++ ...Type=String_implementations=6.verified.txt | 121 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 85 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 86 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 86 ++++++++ ...ingType=Int_implementations=0.verified.txt | 84 ++++++++ ...ingType=Int_implementations=2.verified.txt | 84 ++++++++ ...ingType=Int_implementations=4.verified.txt | 85 ++++++++ ...ingType=Int_implementations=6.verified.txt | 85 ++++++++ ...ngType=Long_implementations=0.verified.txt | 84 ++++++++ ...ngType=Long_implementations=2.verified.txt | 84 ++++++++ ...ngType=Long_implementations=4.verified.txt | 85 ++++++++ ...ngType=Long_implementations=6.verified.txt | 85 ++++++++ ...ransitNewId_implementations=0.verified.txt | 85 ++++++++ ...ransitNewId_implementations=2.verified.txt | 85 ++++++++ ...ransitNewId_implementations=4.verified.txt | 86 ++++++++ ...ransitNewId_implementations=6.verified.txt | 86 ++++++++ ...lableString_implementations=0.verified.txt | 107 ++++++++++ ...lableString_implementations=2.verified.txt | 107 ++++++++++ ...lableString_implementations=4.verified.txt | 117 +++++++++++ ...lableString_implementations=6.verified.txt | 117 +++++++++++ ...Type=String_implementations=0.verified.txt | 93 +++++++++ ...Type=String_implementations=2.verified.txt | 93 +++++++++ ...Type=String_implementations=4.verified.txt | 103 ++++++++++ ...Type=String_implementations=6.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=0.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 127 ++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 128 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 128 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 126 ++++++++++++ ...ingType=Int_implementations=2.verified.txt | 126 ++++++++++++ ...ingType=Int_implementations=4.verified.txt | 127 ++++++++++++ ...ingType=Int_implementations=6.verified.txt | 127 ++++++++++++ ...ngType=Long_implementations=0.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 128 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 129 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 129 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 135 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 136 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 136 ++++++++++++ ...lableString_implementations=0.verified.txt | 150 ++++++++++++++ ...lableString_implementations=2.verified.txt | 150 ++++++++++++++ ...lableString_implementations=4.verified.txt | 160 +++++++++++++++ ...lableString_implementations=6.verified.txt | 160 +++++++++++++++ ...Type=String_implementations=0.verified.txt | 131 ++++++++++++ ...Type=String_implementations=2.verified.txt | 131 ++++++++++++ ...Type=String_implementations=4.verified.txt | 141 +++++++++++++ ...Type=String_implementations=6.verified.txt | 141 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 61 ++++++ ...ngType=Guid_implementations=2.verified.txt | 61 ++++++ ...ngType=Guid_implementations=4.verified.txt | 62 ++++++ ...ngType=Guid_implementations=6.verified.txt | 62 ++++++ ...ingType=Int_implementations=0.verified.txt | 60 ++++++ ...ingType=Int_implementations=2.verified.txt | 60 ++++++ ...ingType=Int_implementations=4.verified.txt | 61 ++++++ ...ingType=Int_implementations=6.verified.txt | 61 ++++++ ...ngType=Long_implementations=0.verified.txt | 60 ++++++ ...ngType=Long_implementations=2.verified.txt | 60 ++++++ ...ngType=Long_implementations=4.verified.txt | 61 ++++++ ...ngType=Long_implementations=6.verified.txt | 61 ++++++ ...ransitNewId_implementations=0.verified.txt | 61 ++++++ ...ransitNewId_implementations=2.verified.txt | 61 ++++++ ...ransitNewId_implementations=4.verified.txt | 62 ++++++ ...ransitNewId_implementations=6.verified.txt | 62 ++++++ ...lableString_implementations=0.verified.txt | 70 +++++++ ...lableString_implementations=2.verified.txt | 70 +++++++ ...lableString_implementations=4.verified.txt | 80 ++++++++ ...lableString_implementations=6.verified.txt | 80 ++++++++ ...Type=String_implementations=0.verified.txt | 70 +++++++ ...Type=String_implementations=2.verified.txt | 70 +++++++ ...Type=String_implementations=4.verified.txt | 80 ++++++++ ...Type=String_implementations=6.verified.txt | 80 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 103 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 104 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 104 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 102 +++++++++ ...ingType=Int_implementations=2.verified.txt | 102 +++++++++ ...ingType=Int_implementations=4.verified.txt | 103 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 103 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 104 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 105 ++++++++++ ...ngType=Long_implementations=6.verified.txt | 105 ++++++++++ ...ransitNewId_implementations=0.verified.txt | 111 ++++++++++ ...ransitNewId_implementations=2.verified.txt | 111 ++++++++++ ...ransitNewId_implementations=4.verified.txt | 112 ++++++++++ ...ransitNewId_implementations=6.verified.txt | 112 ++++++++++ ...lableString_implementations=0.verified.txt | 113 ++++++++++ ...lableString_implementations=2.verified.txt | 113 ++++++++++ ...lableString_implementations=4.verified.txt | 123 +++++++++++ ...lableString_implementations=6.verified.txt | 123 +++++++++++ ...Type=String_implementations=0.verified.txt | 108 ++++++++++ ...Type=String_implementations=2.verified.txt | 108 ++++++++++ ...Type=String_implementations=4.verified.txt | 118 +++++++++++ ...Type=String_implementations=6.verified.txt | 118 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=2.verified.txt | 82 ++++++++ ...ngType=Guid_implementations=4.verified.txt | 83 ++++++++ ...ngType=Guid_implementations=6.verified.txt | 83 ++++++++ ...ingType=Int_implementations=0.verified.txt | 81 ++++++++ ...ingType=Int_implementations=2.verified.txt | 81 ++++++++ ...ingType=Int_implementations=4.verified.txt | 82 ++++++++ ...ingType=Int_implementations=6.verified.txt | 82 ++++++++ ...ngType=Long_implementations=0.verified.txt | 81 ++++++++ ...ngType=Long_implementations=2.verified.txt | 81 ++++++++ ...ngType=Long_implementations=4.verified.txt | 82 ++++++++ ...ngType=Long_implementations=6.verified.txt | 82 ++++++++ ...ransitNewId_implementations=0.verified.txt | 82 ++++++++ ...ransitNewId_implementations=2.verified.txt | 82 ++++++++ ...ransitNewId_implementations=4.verified.txt | 83 ++++++++ ...ransitNewId_implementations=6.verified.txt | 83 ++++++++ ...lableString_implementations=0.verified.txt | 97 +++++++++ ...lableString_implementations=2.verified.txt | 97 +++++++++ ...lableString_implementations=4.verified.txt | 107 ++++++++++ ...lableString_implementations=6.verified.txt | 107 ++++++++++ ...Type=String_implementations=0.verified.txt | 90 ++++++++ ...Type=String_implementations=2.verified.txt | 90 ++++++++ ...Type=String_implementations=4.verified.txt | 100 +++++++++ ...Type=String_implementations=6.verified.txt | 100 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 124 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 125 ++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 125 ++++++++++++ ...ingType=Int_implementations=0.verified.txt | 123 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 123 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 124 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 124 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 125 ++++++++++++ ...ngType=Long_implementations=2.verified.txt | 125 ++++++++++++ ...ngType=Long_implementations=4.verified.txt | 126 ++++++++++++ ...ngType=Long_implementations=6.verified.txt | 126 ++++++++++++ ...ransitNewId_implementations=0.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 132 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 133 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 133 ++++++++++++ ...lableString_implementations=0.verified.txt | 140 +++++++++++++ ...lableString_implementations=2.verified.txt | 140 +++++++++++++ ...lableString_implementations=4.verified.txt | 150 ++++++++++++++ ...lableString_implementations=6.verified.txt | 150 ++++++++++++++ ...Type=String_implementations=0.verified.txt | 128 ++++++++++++ ...Type=String_implementations=2.verified.txt | 128 ++++++++++++ ...Type=String_implementations=4.verified.txt | 138 +++++++++++++ ...Type=String_implementations=6.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 75 +++++++ ...ngType=Guid_implementations=2.verified.txt | 75 +++++++ ...ngType=Guid_implementations=4.verified.txt | 76 +++++++ ...ngType=Guid_implementations=6.verified.txt | 76 +++++++ ...ingType=Int_implementations=0.verified.txt | 74 +++++++ ...ingType=Int_implementations=2.verified.txt | 74 +++++++ ...ingType=Int_implementations=4.verified.txt | 75 +++++++ ...ingType=Int_implementations=6.verified.txt | 75 +++++++ ...ngType=Long_implementations=0.verified.txt | 74 +++++++ ...ngType=Long_implementations=2.verified.txt | 74 +++++++ ...ngType=Long_implementations=4.verified.txt | 75 +++++++ ...ngType=Long_implementations=6.verified.txt | 75 +++++++ ...ransitNewId_implementations=0.verified.txt | 75 +++++++ ...ransitNewId_implementations=2.verified.txt | 75 +++++++ ...ransitNewId_implementations=4.verified.txt | 76 +++++++ ...ransitNewId_implementations=6.verified.txt | 76 +++++++ ...lableString_implementations=0.verified.txt | 91 +++++++++ ...lableString_implementations=2.verified.txt | 91 +++++++++ ...lableString_implementations=4.verified.txt | 101 +++++++++ ...lableString_implementations=6.verified.txt | 101 +++++++++ ...Type=String_implementations=0.verified.txt | 84 ++++++++ ...Type=String_implementations=2.verified.txt | 84 ++++++++ ...Type=String_implementations=4.verified.txt | 94 +++++++++ ...Type=String_implementations=6.verified.txt | 94 +++++++++ ...ngType=Guid_implementations=0.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=2.verified.txt | 117 +++++++++++ ...ngType=Guid_implementations=4.verified.txt | 118 +++++++++++ ...ngType=Guid_implementations=6.verified.txt | 118 +++++++++++ ...ingType=Int_implementations=0.verified.txt | 116 +++++++++++ ...ingType=Int_implementations=2.verified.txt | 116 +++++++++++ ...ingType=Int_implementations=4.verified.txt | 117 +++++++++++ ...ingType=Int_implementations=6.verified.txt | 117 +++++++++++ ...ngType=Long_implementations=0.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=2.verified.txt | 118 +++++++++++ ...ngType=Long_implementations=4.verified.txt | 119 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 119 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 125 ++++++++++++ ...ransitNewId_implementations=2.verified.txt | 125 ++++++++++++ ...ransitNewId_implementations=4.verified.txt | 126 ++++++++++++ ...ransitNewId_implementations=6.verified.txt | 126 ++++++++++++ ...lableString_implementations=0.verified.txt | 134 ++++++++++++ ...lableString_implementations=2.verified.txt | 134 ++++++++++++ ...lableString_implementations=4.verified.txt | 144 +++++++++++++ ...lableString_implementations=6.verified.txt | 144 +++++++++++++ ...Type=String_implementations=0.verified.txt | 122 +++++++++++ ...Type=String_implementations=2.verified.txt | 122 +++++++++++ ...Type=String_implementations=4.verified.txt | 132 ++++++++++++ ...Type=String_implementations=6.verified.txt | 132 ++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 96 +++++++++ ...ngType=Guid_implementations=2.verified.txt | 96 +++++++++ ...ngType=Guid_implementations=4.verified.txt | 97 +++++++++ ...ngType=Guid_implementations=6.verified.txt | 97 +++++++++ ...ingType=Int_implementations=0.verified.txt | 95 +++++++++ ...ingType=Int_implementations=2.verified.txt | 95 +++++++++ ...ingType=Int_implementations=4.verified.txt | 96 +++++++++ ...ingType=Int_implementations=6.verified.txt | 96 +++++++++ ...ngType=Long_implementations=0.verified.txt | 95 +++++++++ ...ngType=Long_implementations=2.verified.txt | 95 +++++++++ ...ngType=Long_implementations=4.verified.txt | 96 +++++++++ ...ngType=Long_implementations=6.verified.txt | 96 +++++++++ ...ransitNewId_implementations=0.verified.txt | 96 +++++++++ ...ransitNewId_implementations=2.verified.txt | 96 +++++++++ ...ransitNewId_implementations=4.verified.txt | 97 +++++++++ ...ransitNewId_implementations=6.verified.txt | 97 +++++++++ ...lableString_implementations=0.verified.txt | 118 +++++++++++ ...lableString_implementations=2.verified.txt | 118 +++++++++++ ...lableString_implementations=4.verified.txt | 128 ++++++++++++ ...lableString_implementations=6.verified.txt | 128 ++++++++++++ ...Type=String_implementations=0.verified.txt | 104 ++++++++++ ...Type=String_implementations=2.verified.txt | 104 ++++++++++ ...Type=String_implementations=4.verified.txt | 114 +++++++++++ ...Type=String_implementations=6.verified.txt | 114 +++++++++++ ...ngType=Guid_implementations=0.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=2.verified.txt | 138 +++++++++++++ ...ngType=Guid_implementations=4.verified.txt | 139 +++++++++++++ ...ngType=Guid_implementations=6.verified.txt | 139 +++++++++++++ ...ingType=Int_implementations=0.verified.txt | 137 +++++++++++++ ...ingType=Int_implementations=2.verified.txt | 137 +++++++++++++ ...ingType=Int_implementations=4.verified.txt | 138 +++++++++++++ ...ingType=Int_implementations=6.verified.txt | 138 +++++++++++++ ...ngType=Long_implementations=0.verified.txt | 139 +++++++++++++ ...ngType=Long_implementations=2.verified.txt | 139 +++++++++++++ ...ngType=Long_implementations=4.verified.txt | 140 +++++++++++++ ...ngType=Long_implementations=6.verified.txt | 140 +++++++++++++ ...ransitNewId_implementations=0.verified.txt | 146 +++++++++++++ ...ransitNewId_implementations=2.verified.txt | 146 +++++++++++++ ...ransitNewId_implementations=4.verified.txt | 147 +++++++++++++ ...ransitNewId_implementations=6.verified.txt | 147 +++++++++++++ ...lableString_implementations=0.verified.txt | 161 +++++++++++++++ ...lableString_implementations=2.verified.txt | 161 +++++++++++++++ ...lableString_implementations=4.verified.txt | 171 ++++++++++++++++ ...lableString_implementations=6.verified.txt | 171 ++++++++++++++++ ...Type=String_implementations=0.verified.txt | 142 +++++++++++++ ...Type=String_implementations=2.verified.txt | 142 +++++++++++++ ...Type=String_implementations=4.verified.txt | 152 ++++++++++++++ ...Type=String_implementations=6.verified.txt | 152 ++++++++++++++ ...ngType=Guid_implementations=0.verified.txt | 68 ++++++ ...ngType=Guid_implementations=2.verified.txt | 68 ++++++ ...ngType=Guid_implementations=4.verified.txt | 69 +++++++ ...ngType=Guid_implementations=6.verified.txt | 69 +++++++ ...ingType=Int_implementations=0.verified.txt | 68 ++++++ ...ingType=Int_implementations=2.verified.txt | 68 ++++++ ...ingType=Int_implementations=4.verified.txt | 69 +++++++ ...ingType=Int_implementations=6.verified.txt | 69 +++++++ ...ngType=Long_implementations=0.verified.txt | 69 +++++++ ...ngType=Long_implementations=2.verified.txt | 69 +++++++ ...ngType=Long_implementations=4.verified.txt | 70 +++++++ ...ngType=Long_implementations=6.verified.txt | 70 +++++++ ...ransitNewId_implementations=0.verified.txt | 68 ++++++ ...ransitNewId_implementations=2.verified.txt | 68 ++++++ ...ransitNewId_implementations=4.verified.txt | 69 +++++++ ...ransitNewId_implementations=6.verified.txt | 69 +++++++ ...lableString_implementations=0.verified.txt | 78 +++++++ ...lableString_implementations=2.verified.txt | 78 +++++++ ...lableString_implementations=4.verified.txt | 88 ++++++++ ...lableString_implementations=6.verified.txt | 88 ++++++++ ...Type=String_implementations=0.verified.txt | 76 +++++++ ...Type=String_implementations=2.verified.txt | 76 +++++++ ...Type=String_implementations=4.verified.txt | 86 ++++++++ ...Type=String_implementations=6.verified.txt | 86 ++++++++ ...ngType=Guid_implementations=0.verified.txt | 110 ++++++++++ ...ngType=Guid_implementations=2.verified.txt | 110 ++++++++++ ...ngType=Guid_implementations=4.verified.txt | 111 ++++++++++ ...ngType=Guid_implementations=6.verified.txt | 111 ++++++++++ ...ingType=Int_implementations=0.verified.txt | 110 ++++++++++ ...ingType=Int_implementations=2.verified.txt | 110 ++++++++++ ...ingType=Int_implementations=4.verified.txt | 111 ++++++++++ ...ingType=Int_implementations=6.verified.txt | 111 ++++++++++ ...ngType=Long_implementations=0.verified.txt | 113 ++++++++++ ...ngType=Long_implementations=2.verified.txt | 113 ++++++++++ ...ngType=Long_implementations=4.verified.txt | 114 +++++++++++ ...ngType=Long_implementations=6.verified.txt | 114 +++++++++++ ...ransitNewId_implementations=0.verified.txt | 118 +++++++++++ ...ransitNewId_implementations=2.verified.txt | 118 +++++++++++ ...ransitNewId_implementations=4.verified.txt | 119 +++++++++++ ...ransitNewId_implementations=6.verified.txt | 119 +++++++++++ ...lableString_implementations=0.verified.txt | 121 +++++++++++ ...lableString_implementations=2.verified.txt | 121 +++++++++++ ...lableString_implementations=4.verified.txt | 131 ++++++++++++ ...lableString_implementations=6.verified.txt | 131 ++++++++++++ ...Type=String_implementations=0.verified.txt | 114 +++++++++++ ...Type=String_implementations=2.verified.txt | 114 +++++++++++ ...Type=String_implementations=4.verified.txt | 124 +++++++++++ ...Type=String_implementations=6.verified.txt | 124 +++++++++++ .../StronglyTypedIdGeneratorTests.cs | 1 + 1561 files changed, 170786 insertions(+), 2 deletions(-) create mode 100644 src/StronglyTypedIds/Templates/Guid/Guid_SwaggerSchemaFilter.cs create mode 100644 src/StronglyTypedIds/Templates/Int/Int_SwaggerSchemaFilter.cs create mode 100644 src/StronglyTypedIds/Templates/Long/Long_SwaggerSchemaFilter.cs create mode 100644 src/StronglyTypedIds/Templates/NewId/NewId_SwaggerSchemaFilter.cs create mode 100644 src/StronglyTypedIds/Templates/NullableString/NullableString_SwaggerSchemaFilter.cs create mode 100644 src/StronglyTypedIds/Templates/String/String_SwaggerSchemaFilter.cs create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt diff --git a/README.md b/README.md index 094fdf587..dff946975 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ To use the the [StronglyTypedId NuGet package](https://www.nuget.org/packages/St * [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/) (optional, only required if [generating a System.Text `JsonConverter`](https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-2/#creating-a-custom-jsonconverter)). Note that in .NET Core apps, you will likely already reference this project via transitive dependencies. * [Dapper](https://www.nuget.org/packages/Dapper/) (optional, only required if [generating a type mapper](https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-3/#interfacing-with-external-system-using-strongly-typed-ids)) * [EF Core](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) (optional, only required if [generating an EF Core ValueConverter](https://andrewlock.net/strongly-typed-ids-in-ef-core-using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-4/)) +* [Swagger Annotations](https://www.nuget.org/packages/Swashbuckle.AspNetCore.Annotations) (optional, only required if [generating an Swagger Schema Filter](#openapiswagger-specification) + To install the packages, add the references to your _csproj_ file, for example by running @@ -160,6 +162,18 @@ public partial struct OrderId { } public partial struct UserId { } ``` +## OpenApi/Swagger Specification + +If you wish to use an ID in your Swagger models and want to have schema and model sample reflecting the ID backingfield type you will need: +- Install [Swagger Annotations](https://www.nuget.org/packages/Swashbuckle.AspNetCore.Annotations) `>=5.0.0` +- Enable annotation in swagger gen with `services.AddSwaggerGen(c => c.EnableAnnotations());` +- Use the converter flag `StronglyTypedIdConverter.SwaggerSchemaFilter` on the ID decorator. eg: + ```csharp + [StronglyTypedId( + backingType: StronglyTypedIdBackingType.Int, + converters: StronglyTypedIdConverter.SwaggerSchemaFilter | StronglyTypedIdConverter.SystemTextJson)] + public partial struct UserId { } + ``` ## Embedding the attributes in your project @@ -253,4 +267,4 @@ The `struct`s you decorate with the `StronglyTypedId` attribute must be marked ` `StronglyTypedId` wouldn't work if not for [AArnott's CodeGeneration.Roslyn](https://github.com/AArnott/CodeGeneration.Roslyn) library. -The build process and general design of the library was modelled on the [RecordGenerator](https://github.com/amis92/RecordGenerator/blob/master/README.md) project, which is similar to this project, but can be used to generate immutable Record types. \ No newline at end of file +The build process and general design of the library was modelled on the [RecordGenerator](https://github.com/amis92/RecordGenerator/blob/master/README.md) project, which is similar to this project, but can be used to generate immutable Record types. diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs b/src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs index 599a51409..4dad18ae1 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs @@ -46,5 +46,11 @@ public enum StronglyTypedIdConverter /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } \ No newline at end of file diff --git a/src/StronglyTypedIds/EmbeddedSources.cs b/src/StronglyTypedIds/EmbeddedSources.cs index e1f229779..1c6d7e0b5 100644 --- a/src/StronglyTypedIds/EmbeddedSources.cs +++ b/src/StronglyTypedIds/EmbeddedSources.cs @@ -25,6 +25,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_SwaggerSchemaFilter.cs"), false ); @@ -37,6 +38,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_SwaggerSchemaFilter.cs"), false ); @@ -49,6 +51,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_SwaggerSchemaFilter.cs"), false ); @@ -61,6 +64,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_SwaggerSchemaFilter.cs"), false ); @@ -73,6 +77,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_SwaggerSchemaFilter.cs"), true ); @@ -85,12 +90,14 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_SwaggerSchemaFilter.cs"), false ); internal const string TypeConverterAttributeSource = " [System.ComponentModel.TypeConverter(typeof(TESTIDTypeConverter))]"; internal const string NewtonsoftJsonAttributeSource = " [Newtonsoft.Json.JsonConverter(typeof(TESTIDNewtonsoftJsonConverter))]"; internal const string SystemTextJsonAttributeSource = " [System.Text.Json.Serialization.JsonConverter(typeof(TESTIDSystemTextJsonConverter))]"; + internal const string SwaggerSchemaFilterAttributeSource = " [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(TESTIDSchemaFilter))]"; internal static string LoadEmbeddedResource(string resourceName) { @@ -108,6 +115,7 @@ internal static string LoadEmbeddedResource(string resourceName) public readonly struct ResourceCollection { + public string SwaggerSchemaFilter { get; } public string Header { get; } public bool NullableEnable { get; } public string BaseId { get; } @@ -127,8 +135,10 @@ public ResourceCollection( string efCoreValueConverter, string dapperTypeHandler, string comparable, + string swaggerSchemaFilter, bool nullableEnable) { + SwaggerSchemaFilter = swaggerSchemaFilter; BaseId = baseId; Newtonsoft = newtonsoft; SystemTextJson = systemTextJson; diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index e33515310..5ed4a79d4 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -64,6 +64,7 @@ static string CreateId( var hasNamespace = !string.IsNullOrEmpty(idNamespace); + var useSchemaFilter = converters.IsSet(StronglyTypedIdConverter.SwaggerSchemaFilter); var useTypeConverter = converters.IsSet(StronglyTypedIdConverter.TypeConverter); var useNewtonsoftJson = converters.IsSet(StronglyTypedIdConverter.NewtonsoftJson); var useSystemTextJson = converters.IsSet(StronglyTypedIdConverter.SystemTextJson); @@ -122,6 +123,12 @@ static string CreateId( sb.AppendLine(EmbeddedSources.TypeConverterAttributeSource); } + if (useSchemaFilter) + { + sb.AppendLine(EmbeddedSources.SwaggerSchemaFilterAttributeSource); + } + + sb.Append(resources.BaseId); ReplaceInterfaces(sb, useIEquatable, useIComparable); @@ -157,6 +164,11 @@ static string CreateId( sb.AppendLine(resources.SystemTextJson); } + if (useSchemaFilter) + { + sb.AppendLine(resources.SwaggerSchemaFilter); + } + sb.Replace("TESTID", idName); sb.AppendLine(@" }"); diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/Guid/Guid_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..de06e10c0 --- /dev/null +++ b/src/StronglyTypedIds/Templates/Guid/Guid_SwaggerSchemaFilter.cs @@ -0,0 +1,13 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } \ No newline at end of file diff --git a/src/StronglyTypedIds/Templates/Int/Int_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/Int/Int_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..34b0d8919 --- /dev/null +++ b/src/StronglyTypedIds/Templates/Int/Int_SwaggerSchemaFilter.cs @@ -0,0 +1,13 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } \ No newline at end of file diff --git a/src/StronglyTypedIds/Templates/Long/Long_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/Long/Long_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..0d3508292 --- /dev/null +++ b/src/StronglyTypedIds/Templates/Long/Long_SwaggerSchemaFilter.cs @@ -0,0 +1,13 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } \ No newline at end of file diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/NewId/NewId_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..de06e10c0 --- /dev/null +++ b/src/StronglyTypedIds/Templates/NewId/NewId_SwaggerSchemaFilter.cs @@ -0,0 +1,13 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } \ No newline at end of file diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..daea45b8d --- /dev/null +++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_SwaggerSchemaFilter.cs @@ -0,0 +1,14 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } \ No newline at end of file diff --git a/src/StronglyTypedIds/Templates/String/String_SwaggerSchemaFilter.cs b/src/StronglyTypedIds/Templates/String/String_SwaggerSchemaFilter.cs new file mode 100644 index 000000000..1073bbf27 --- /dev/null +++ b/src/StronglyTypedIds/Templates/String/String_SwaggerSchemaFilter.cs @@ -0,0 +1,14 @@ + + class TESTIDSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } \ No newline at end of file diff --git a/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs b/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs index 2905f70e6..2ce11869c 100644 --- a/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs @@ -325,6 +325,28 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerGuidId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("string", schema.Type); + Assert.Equal("uuid", schema.Format); + } +#endif + public class TestDbContext : DbContext { public DbSet Entities { get; set; } @@ -344,6 +366,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .ValueGeneratedNever(); }); } + } public class TestEntity diff --git a/test/StronglyTypedIds.IntegrationTests/IntIdTests.cs b/test/StronglyTypedIds.IntegrationTests/IntIdTests.cs index e2c48be64..90000025c 100644 --- a/test/StronglyTypedIds.IntegrationTests/IntIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/IntIdTests.cs @@ -318,6 +318,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerIntId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("integer", schema.Type); + Assert.Equal("int32", schema.Format); + } +#endif public class TestDbContext : DbContext { public DbSet Entities { get; set; } diff --git a/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs b/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs index b2f70dbcb..404ca9257 100644 --- a/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs @@ -319,6 +319,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerLongId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("integer", schema.Type); + Assert.Equal("int64", schema.Format); + } +#endif public class TestDbContext : DbContext { public DbSet Entities { get; set; } diff --git a/test/StronglyTypedIds.IntegrationTests/MassTransitNewIdTests.cs b/test/StronglyTypedIds.IntegrationTests/MassTransitNewIdTests.cs index e6dce6d74..ef1e75f8d 100644 --- a/test/StronglyTypedIds.IntegrationTests/MassTransitNewIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/MassTransitNewIdTests.cs @@ -327,6 +327,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerNewIdId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("string", schema.Type); + Assert.Equal("uuid", schema.Format); + } +#endif public class TestDbContext : DbContext { public DbSet Entities { get; set; } diff --git a/test/StronglyTypedIds.IntegrationTests/NullableStringIdTests.cs b/test/StronglyTypedIds.IntegrationTests/NullableStringIdTests.cs index 877d3e4d1..fbc71fff0 100644 --- a/test/StronglyTypedIds.IntegrationTests/NullableStringIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/NullableStringIdTests.cs @@ -381,6 +381,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerNullableStringId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("string", schema.Type); + Assert.Equal("", schema.Format); + } +#endif public class TestDbContext : DbContext { public DbSet Entities { get; set; } diff --git a/test/StronglyTypedIds.IntegrationTests/StringIdTests.cs b/test/StronglyTypedIds.IntegrationTests/StringIdTests.cs index 70508222c..76b9bdd3e 100644 --- a/test/StronglyTypedIds.IntegrationTests/StringIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/StringIdTests.cs @@ -317,6 +317,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } #endif +#if NET5_0_OR_GREATER + [Fact] + public void CanShowImplementationTypeExample_WithSwaggerSchemaFilter() + { + var schemaGenerator = new Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator( + new Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions(), + new Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver( + new System.Text.Json.JsonSerializerOptions())); + var provider = Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider( + new Microsoft.Extensions.DependencyInjection.ServiceCollection()); + var schemaFilter = new Swashbuckle.AspNetCore.Annotations.AnnotationsSchemaFilter(provider); + var schemaRepository = new Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository(); + + var idType = typeof(SwaggerStringId); + var schema = schemaGenerator.GenerateSchema(idType, schemaRepository); + schemaFilter.Apply(schema, new Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext(idType, schemaGenerator, schemaRepository)); + + Assert.Equal("string", schema.Type); + Assert.Equal("", schema.Format); + } +#endif public class TestDbContext : DbContext { public DbSet Entities { get; set; } diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 82530749f..a6c3bf1f9 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -20,13 +20,14 @@ - + + diff --git a/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs b/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs index 9ad651d72..dcafd4207 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs @@ -29,6 +29,11 @@ public partial struct EfCoreGuidId { } [StronglyTypedId(converters: StronglyTypedIdConverter.DapperTypeHandler)] public partial struct DapperGuidId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(converters: StronglyTypedIdConverter.SwaggerSchemaFilter)] + public partial struct SwaggerGuidId { } +#endif + [StronglyTypedId(implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothGuidId { } diff --git a/test/StronglyTypedIds.IntegrationTests/Types/IntId.cs b/test/StronglyTypedIds.IntegrationTests/Types/IntId.cs index 15316b98a..809335237 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/IntId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/IntId.cs @@ -26,6 +26,11 @@ public partial struct EfCoreIntId { } [StronglyTypedId(converters: StronglyTypedIdConverter.DapperTypeHandler, backingType: StronglyTypedIdBackingType.Int)] public partial struct DapperIntId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(converters: StronglyTypedIdConverter.SwaggerSchemaFilter, backingType: StronglyTypedIdBackingType.Int)] + public partial struct SwaggerIntId { } +#endif + [StronglyTypedId(backingType: StronglyTypedIdBackingType.Int, implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothIntId { } diff --git a/test/StronglyTypedIds.IntegrationTests/Types/LongId.cs b/test/StronglyTypedIds.IntegrationTests/Types/LongId.cs index 5a1081bb8..b3fcf5667 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/LongId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/LongId.cs @@ -26,6 +26,11 @@ public partial struct EfCoreLongId { } [StronglyTypedId(converters: StronglyTypedIdConverter.DapperTypeHandler, backingType: StronglyTypedIdBackingType.Long)] public partial struct DapperLongId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(converters: StronglyTypedIdConverter.SwaggerSchemaFilter, backingType: StronglyTypedIdBackingType.Long)] + public partial struct SwaggerLongId { } +#endif + [StronglyTypedId(backingType: StronglyTypedIdBackingType.Long, implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothLongId { } diff --git a/test/StronglyTypedIds.IntegrationTests/Types/NewIdId.cs b/test/StronglyTypedIds.IntegrationTests/Types/NewIdId.cs index 0be4ce4c9..6e6f5b75e 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/NewIdId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/NewIdId.cs @@ -29,6 +29,11 @@ public partial struct EfCoreNewIdId { } [StronglyTypedId(backingType: StronglyTypedIdBackingType.MassTransitNewId, converters: StronglyTypedIdConverter.DapperTypeHandler)] public partial struct DapperNewIdId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(backingType: StronglyTypedIdBackingType.MassTransitNewId, converters: StronglyTypedIdConverter.SwaggerSchemaFilter)] + public partial struct SwaggerNewIdId { } +#endif + [StronglyTypedId(backingType: StronglyTypedIdBackingType.MassTransitNewId, implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothNewIdId { } diff --git a/test/StronglyTypedIds.IntegrationTests/Types/NullableStringId.cs b/test/StronglyTypedIds.IntegrationTests/Types/NullableStringId.cs index d51e901a1..b98962246 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/NullableStringId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/NullableStringId.cs @@ -26,6 +26,11 @@ public partial struct EfCoreNullableStringId { } [StronglyTypedId(converters: StronglyTypedIdConverter.DapperTypeHandler, backingType: StronglyTypedIdBackingType.NullableString)] public partial struct DapperNullableStringId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(converters: StronglyTypedIdConverter.SwaggerSchemaFilter, backingType: StronglyTypedIdBackingType.NullableString)] + public partial struct SwaggerNullableStringId { } +#endif + [StronglyTypedId(backingType: StronglyTypedIdBackingType.NullableString, implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothNullableStringId { } diff --git a/test/StronglyTypedIds.IntegrationTests/Types/StringId.cs b/test/StronglyTypedIds.IntegrationTests/Types/StringId.cs index 5e7cdfa57..bf8a81afa 100644 --- a/test/StronglyTypedIds.IntegrationTests/Types/StringId.cs +++ b/test/StronglyTypedIds.IntegrationTests/Types/StringId.cs @@ -26,6 +26,11 @@ public partial struct EfCoreStringId { } [StronglyTypedId(converters: StronglyTypedIdConverter.DapperTypeHandler, backingType: StronglyTypedIdBackingType.String)] public partial struct DapperStringId { } +#if NET5_0_OR_GREATER + [StronglyTypedId(converters: StronglyTypedIdConverter.SwaggerSchemaFilter, backingType: StronglyTypedIdBackingType.String)] + public partial struct SwaggerStringId { } +#endif + [StronglyTypedId(backingType: StronglyTypedIdBackingType.String, implementations: StronglyTypedIdImplementations.IEquatable | StronglyTypedIdImplementations.IComparable)] public partial struct BothStringId { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt index 32b324616..f9fffe68a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt @@ -59,6 +59,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..229ebb021 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..0f97932a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ea3ade611 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..f14ab3877 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..0e69fb94b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..1b4e03230 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..59db11881 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..4c1d4947a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..9ce5d9bae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..711654ffc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..fce195165 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..fed90704a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..7d7ee092c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..90fa44401 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..2fd79a2b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..6d82a6b07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..4fabc3182 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..858205dda --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..34c44711e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..400a376b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..0606930d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..88ed2aa52 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..9c2dfd631 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..1eb3f4c2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c1d784b3a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..50aa16327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..7abca0a14 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..771380c14 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..9ab559bb0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..e86a12a94 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..3202f6008 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..5e26639ca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..faf5c1973 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..7760b7b34 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..254b1ea77 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..b18e5d542 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..a212749a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..6abca8a56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..620c1710f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..8bf8dd26a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..3efdfa947 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..f20a57ef8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..8fa913aea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..aeda230a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..c8fade53a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..6e46f01aa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..0d5185930 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..4858dd900 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..5cd6629f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..2537096c5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..86563a15b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..64aa3964a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..583ffca7f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..1d1e03578 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..23fa07284 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..7fd31a405 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..5c58cc94f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..aa75d90bd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..428f9e692 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..b860c0820 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..95a2049ba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..692c255cc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..6d04448d3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..f99fc8b1b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..cc74782c6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..afe6106de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..afe6d365e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..bbad1c5fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..847e78d87 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..fb897c9bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..10c531999 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..5ea362830 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..317a1bf6c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a9e45110f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ee0d1dea5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..10aa0e402 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..de5067969 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..7fac279df --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..609dd414c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..3552bb9b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..c85ca7254 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..c75af94ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..46b3ade84 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..5ac620d53 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..8c5557f74 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..647dbcac3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..9c7a2f509 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..27ae17dfd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..4cfb8a161 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..ee946c796 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..c834eeb84 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..158eff403 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..7855ac9d7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..cce3a3482 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..e48bd4fa6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..46b8aa422 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..b5c8a5a96 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..e81138541 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..79949c17c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..8da0f4a7f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..2f30c58a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..f62caac08 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..1e2bcb601 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..944fd91dd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..533a2fad1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..a1b9e3924 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..1a3242d73 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..4210beef4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..5da86f568 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..2d50ea59f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..b60f9136c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..a2ba5c42b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..e9e229af8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..5e85b2290 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..0e0991296 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..a98851a7c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..292d71441 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..948e340b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..7bc2194ee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..633d4699c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..77a65b44c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..8187ec79d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..99b3cf5dc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..f98c47271 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..dbb8209f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..923beaffa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4cdf15814 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..611234937 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..21234322f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..dbb963bb9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..90c4c80f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..389d5fdfc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..59da85df0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..84a3a747d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..438c83476 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..2594f8cfe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..6ff9daa83 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..86c7e81c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..5fde739e4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,182 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..c017cffcb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,182 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..0b175e035 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..19624a2ce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..5a063a204 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..bde4360d3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..9eb3ca3ed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..6c9819a46 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..d9a68c174 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..aaea91dc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..6e58e080f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..7a50f29a5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4d1a08f67 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..19d1cec60 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..3d126aedd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..e9a30adc1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..8362d54be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..107216968 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..72d5b09da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..16ed66311 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..b599279eb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..703b9b321 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..31e0e37b2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..5ca9449ba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..d42ec6c61 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..00b5cf617 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..a54c38699 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..aa0e9eae7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..69c753b1d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..ba8b5b672 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..1e7c93bb3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..13d76f4ed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..f39de9f13 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..2c31f4952 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..acc106949 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..999fde6cc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..1a77ae8ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..c56f30b87 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..9ba5f1e70 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..7352fe283 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..95cb723ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..41d2e3f30 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..34585f280 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..14ea68983 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..bf93c0841 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..f62c95b9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..2f1e60a45 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..c614d8f17 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..0ffc7d313 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..a32eca9bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..1bd2d8844 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..c8de7350c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..31f08a0fc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..b3347986f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..9af002bb2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a505a658a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..0a0f06c48 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..49ddfcd2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..1c50d26ed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..e07fe3197 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..f19845ca0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..36213fe29 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..cec215a8b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..ebc6df24b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..6c77e3ee4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..34ca3760a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..3d28f4c2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..0f349d3c5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..678a2da5b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..3e7667f2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..33d12a745 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..d8402738b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..6682e3e0f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..e30663635 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..2416cc823 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..2423a5d56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..74be18e21 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..8abd9f152 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..4042ccde0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..7bdff827b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..6c677e208 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..3b697d2b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..03d0c4ae5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..bc8ad6284 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..cd809a2cd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..3d0471a44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..92fe0ec82 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..975d8f384 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..59c2cc6cf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..08c22a22f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..5b2b3c8e4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..c0dd251d0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..29a78158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..3a4bc6061 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..0ee16d6f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..848042432 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..3fb771bb1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..5750c9bed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..2c4d0ce75 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..2675f6257 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..eea7bb6fc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..bac91705c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..656a02f85 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..df05e7bc7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..f42656289 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d93eb098f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..b8d23e1bb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..6cd419417 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4a4dc8636 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..0d233ed93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..286db9d46 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..32e9a48bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..91769108a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..4044361ba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..c4de5aea9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..eb8e6e31a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..70bf726c3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..6df6dee02 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..df972f944 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..7092ad4df --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..c86ab64a9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..5b5e53cb3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..79e03a551 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..4dac6c237 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..929da6071 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..18e4af09c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..5960ca014 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..d4037395e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..421b25aa6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..8d1909f42 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..aef61774a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..983c48f23 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..11d4927f0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..156d09c99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..de22eeb1b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..55a83a1ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..b7734820a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..59e6451b2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..547b0738d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..42de152f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..358283e03 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5fb522786 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..2a2ed1ccb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..58d287155 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..48e30a9ed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,166 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..be7bf278f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,166 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..d19d15a83 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..2be3a09ac --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..540144973 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d9fa17e36 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..9ff87f22a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..ace613db4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..fa9539590 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..3500e2e01 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..c34957da1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..7b1eb108b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..2012d0001 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..1372c471d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..aa5dc7151 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..1d327d41e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0d8564d5e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..88a8a960f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..51371beff --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..32337df1c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..75775341d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..bd59afa50 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..762634825 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..238a53262 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..ef4d5b829 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..5c427d5a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..1087be08e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..ee0e3b705 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..60c0cf89d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..e57b66697 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..689b279f0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f6c64901f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..6dc1b72f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..ba9c0e587 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..b4e3b7140 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..e2e138b6c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..ea4ea86f2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..3b8f6f307 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..11f18e73f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..46bbf48d5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..6dd5202a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..38b553aa0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..28c5f159e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,167 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..07b5f09d8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,167 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..4318dfffa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,168 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..7088765e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,168 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..efc9e06b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,183 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..d577f7959 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,183 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..59bfe48fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,193 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..600fe16c4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,193 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..695aea9a2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..ed406a077 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..32b3f71a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..ec1a4cf85 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt @@ -0,0 +1,172 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..db73d7c72 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..ab67db89c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..2ea30ea87 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..8947aeea4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..939d3d42b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..8a24f91e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..574bf320a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..83dbc8dea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..96e3e86ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..f027024a0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..e613f0509 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..6e94d7b9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..388416ea8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..d9055db66 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..048b12af6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..35f56493c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..2ff3dc771 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..450600ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..0b793df55 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b4ba4183a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..f68abb2a5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..165f19d71 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..fa395e077 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..71a1c0b0c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c37fc53b7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..dde681fe5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..6bb3bbda5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..64f4749c9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..3f1a4f562 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..063ace9a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..5c1dd8b52 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..f43621585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..5703947e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..05b15f21d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..a1a8fdc86 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..95289b405 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..1ffa1ad92 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..c1ad070c0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..59e77a8b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..f859bf143 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..6682424ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..4f423a375 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..4c40b2195 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..9a18511c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..06010874b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..a656d41a4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..f91464035 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..27b4ebc9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..8b5738e05 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a36f6ecbf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ba832c53d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..7db64fc51 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..5ca61086c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..0fca8c172 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..478074271 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d4a5de05f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..7652d3991 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..32b1783d1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..5c4676a4d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..4cfe9e512 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..14440ffb4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..662bfc751 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..85d0c0993 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..3fd9533a2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..71c9f73a4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..37d631d60 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..0686c3acf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..643a14426 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..3000297b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..ce4c75fcf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..4bc54fd0f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d2ac180c7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..cb0548a8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..8870b171b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..3d989ccd1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..25580303d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..2f9c737ac --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..b46a8788b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..814a92d5e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..5a6b204e2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..2b09b935f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..e51f2454a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..b6a171238 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..3bd9697de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..c5a2a572b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..0d9f3550b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..26e8dbfff --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..94e75fd6d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..98852f4a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..f47f6a8ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..4c036d028 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..302c77505 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..fb76ae8a5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..3d72d141f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..daa1ac0b9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d10c3920e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..f8930cb95 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..9414f9710 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..c05fdf6ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..a975a4ee4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..0f64b6473 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..daccd25f9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..cf7c0ec50 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..549360015 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..87bd667ff --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..fffba2829 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..fb11870e4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..77e4c13e6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..fb97bd53a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..8e9eda8b1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..341a2f8ee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5040719b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..2c109942b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..e352d9942 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..11ceeaeab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..e06b9c54a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..176023635 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..db1c7c61b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..f316d1479 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..306955907 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..2cc569e67 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..cadee9de5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..a64ee7c40 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..c28c5c111 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..62cc0ac1c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..353b6bd46 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..69fc7f8fd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..0bf2cfb0c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..127fa9cc2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..64e961809 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c9cbeb718 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..dbf38da5a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..ae37d16e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..806dfbcd5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..390374254 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..bed15e33f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..7c683cfbf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..7c5f4cb29 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..6b6ddee36 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b419a8fa1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..1095a9342 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..83ecf874f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..78d15b5d9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..591ba7a5f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..01ae14b53 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..affd6aef5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..d81ef194e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..37574fcf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..efa618f59 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..54859ce39 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..b46c13c08 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..16196024f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..432556bfc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..91a57ab9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..ec6f934cc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..0ef98800e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..e57a8b0a0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..777f4755c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..3d48388b7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..9b088f1d8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..b7f015cc4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..877f30fc1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..fe098b3a4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..97cc70861 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..40d98184f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..fd6395346 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..126f4ab0b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..c79e8df6f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..3790ff67e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..7c4e1343c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..51b4a4c15 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..a1268db16 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..a1cb3b7ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..a5b0ec3ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..f71130917 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..0946b2acc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..ebdc7c26b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..cc06de890 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..4b6b9fd2c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..b4dbcfeeb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..68189ae94 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..9245a111b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..64404d16f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..909cbea51 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..3f1013154 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..41f9a1ee8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..c0cc6719b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..42e63f7c6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..6d04e06b2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..bcb489e4a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..767710b01 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..4f8df56d8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..168b818e5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..472ebf012 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..3671764de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..ac2c11dc7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..786c2b2af --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..aebcacb76 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..63135873d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d513d8f15 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..c36914d44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..7125e230d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..323d10acd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..845f7defc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..397296490 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..ec425b1ce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..4d4ab00f1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..b8acdba88 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..ab2b32ac6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..9ae7047c8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..bfa51d6d5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..1a053e670 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..0e9120a3d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..173a18603 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..b9fea9451 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..859d4f1bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..0cc311720 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..137d45b60 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..11223600a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..a0f8bd739 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..80fba849c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..3db571a09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..0c60a5cae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..7d9f21e91 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..4adee3d8a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..aa1a3a7eb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..df69a1437 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..7dd1adf15 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..31f18771c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..e4f2558b0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..a285963ee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..aab9e9198 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..aa9d7325a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..3889f1b2c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..5b5786dbc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..62660711f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..2cefad67d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..48aba8ad7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..34fcf093f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..1e9bf40ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..0b023a964 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f83ab9759 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..c77cee59f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..92b7a8ab1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..dd10e6f39 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..6ee6a780f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..d90a5563b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..94cc48e8f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..4da96e7cb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..9a684bbf1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0ad48235a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..e9e49454a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..ce6ce68da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..b0b9c9ddb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..3a8e23090 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..4757316fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..514e0265e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..6026081b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..7e1076586 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..f8e10771b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..39ac1ea70 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..7c17a945e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..c6696416f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..c4af410a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c87dcc389 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..c0c2542bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..3803ac38a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..9faf9cfb5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..6aeb853ac --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..7011b2c6e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..d2f56f074 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..4607107b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..871662de9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..c997e6643 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..852988f03 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..c62a18b7b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..c283d9fdf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..4d6886655 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..b591d94f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..7d966b94c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..9bf6ec191 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..cf5d12c3a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..1533d4e65 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..c6faeb6a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..a359578f9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..082c9f619 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..f21c82008 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..76fcb6e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..61db60659 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..4ca419cdf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..cef3a45e3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d689639e2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..09518e095 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..72d51729a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..b9255dda7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..fb8ec33b8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..fd4cf2b48 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..4b38bbe58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..d68e91f55 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..826898e77 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..0705ad7aa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..8d438a68c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..c292a28cd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..d24faf39f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..b1ff0bfaa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..dba667527 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..c71ac076d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..f51d952c6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..cc88c8f89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..4d4b7c7a0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..05e3a3215 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..548997e28 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..20fca5beb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..7a5b1761c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..c34371f8e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..84e55389f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..c78e15e58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..f98ea2789 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..271e0c6e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..f2f722776 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..7150263cb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..3236405d7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c76c3fee6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..454c06db1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..40fe43481 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..291178c59 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..6d38b1a63 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..0a76879a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..bde8df3d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..688275ca4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..bb364687c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..e6853c333 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..ae80c60b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..f15fc930c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..0168db84c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..2eda7cd13 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..13474b97e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f8f76f4e9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..c7e5b6c67 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d08b3d008 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..010acac36 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..8d6c4f77e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..1fe668f3d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..25a4f6dcd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..79ef7d77f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..a157f0b1a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0ee3e6379 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..9ee6aaede --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..fa727b83b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..b453d815d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..ba58f69ce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..b6bebed58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..4785f4abd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..65b1cd404 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..67e8a47aa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..13ff4f36c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..b53b89322 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..706b08e28 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..190951740 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..7701db3cd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..19dcaa007 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..1876914f2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..b0209023c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..5780d351a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..03edddb56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..cc4b7c547 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4162b32c4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..5bcc9bf93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..26f300d94 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..91d45203e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..8f0a79088 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..840d9f7cb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..ef2d7559f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..107da07c9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..26d0beffe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..2b058b982 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..325bdfdb3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,164 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..379c642c7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,164 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..702a7a499 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,174 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..cbce43d5e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,174 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..f694a8854 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..2c9fa7aee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..4ccc06c79 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..8207ee2bd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..69134f044 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..ed4a9eac2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..8ebf2e466 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..2a33f94e5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..9f1bb8929 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..bb48a5b9c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..94cbf4b58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..870d679a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..56f3553c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..6f141dadf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..9a2fe4685 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..5d4cd5f9c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..20b66b657 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..832ad928e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..5479e7882 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..d98b1c9ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..686f54fa0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..206cf36d1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..c80ce25c0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..fb2c60df6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..7caa650f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..190245d93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..1c917867d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..659df3462 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..e27ab652b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..7ea62a411 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..6eb9d1a1b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..230c821fc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..27024b78f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..2e9219241 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..d1ac39f99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..344ff96d6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..ee2db7c18 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..8599b94bd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..78bac6718 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..2363589b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..5b0dfee9f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..e6363f720 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..d72018828 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..1618ac549 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..b12c7e51e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..14b09e7bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..74462001f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..577112e33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..3d8a0f3de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..7ab0c4cf1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..3792e2100 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..74e792602 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace Some.Namespace +{ + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c770901de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a9b6264a8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..f926e3d1e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..0b4c92fd5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..7f1d75f6e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..fff29a224 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..cc026e3c5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..6f4a5a4c2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..808026446 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..c5cbf7ed3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..1e3aaca7f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..2432ff7e0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..d625fc064 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..67f890457 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..95a5bc656 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..bce3ecf72 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..81c154b52 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..d5aba85f4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..96ab789d3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..39d4fd315 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..a8c8f398b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..1cc61952e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..8d044666c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..f48e5fb7b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..db656b396 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a1610c7ba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..00712b8a5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..0f2a9ad4c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..620112c63 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..191a8323a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..2a5cb4c8c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..7ef9f95e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a9a002179 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..97969f33f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..d757a27f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..216bff854 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..95246c1a9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..65814d4be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..495a250c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..1f087cc27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..ea79f6f25 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..4b1755257 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..5edf036f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..68b1539e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..26c01b319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..afdfd1ab8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..fa311a0c3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d48faf873 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..37f3a930c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..d65b45a40 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..07abd8d61 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..ea27671a2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..470fd8c21 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..2fbac1dc3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..eef0787ee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..765fabbd3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..81e1fe46c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..e0f50aea0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..6722dae0d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..d8c07804d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..04e676115 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..ac5232352 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..4ab683dde --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..d0d6903f9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..5694dee57 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..7361ca4a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..808fd8086 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..fe5afe261 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,109 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..ef32fd2de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..3997fdf33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..c90862e9e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..772074179 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..9b4ad67a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..82be04ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..e159eb253 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..8039775bc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..30cf88406 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..ceead352d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..8ca16c303 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..43391cd4a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..9fe000d10 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..83dfc5b13 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..eb491e9b9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..2b4e30e70 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..041d1c8b1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..820eac099 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..9b866b1f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..568094c3f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..dce400f11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..46ee738ed --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..ddd8806ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..6350c5a59 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..180e8bc9f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..d96e9ccc6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..57ba3e078 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..bd154f9dd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..6ddf400b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..edefd3e19 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..5603a7a97 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..de72a5c9f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..04d5ed600 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..492d4435b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..c2a84beaf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..1ded7de15 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..c4167cfb6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..c9bfa8705 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..fc125fe98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..fba3dc1c5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..458f874bc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..5207c1521 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..965126ffd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..73ed77a4f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..23f2bd09e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..aee381c23 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..8660e9d7d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..83bf235e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..ed4edb68e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..0e2b814b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..f06ad2923 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..ca7781556 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..0fd446f48 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..df585294a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..667c5cc89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..26b52565d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..f6d58a7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..26329815d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..0e15f94a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..26e1f5334 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..24f34e3c6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..ef636c428 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..5b75acd43 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..ba23aaa86 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..4ced0e5ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..4da946e03 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..2752bb172 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..084a8e3a8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..06331293f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..3c2f69cdf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..cc83142c2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..db5ac5e82 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..5beecd415 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..ae2f786e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..8af0551cb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d73f249a2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt @@ -0,0 +1,158 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..1c9d1866b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..7b4eaeabc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..afb853513 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..e77db09d6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..56b534218 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..3dd7ded00 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..8f5083824 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..8d0d182a9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..d38ab64bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..b9cea133d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..61fc5fda3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..277a1515b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..f6db63a1b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..74b66699b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..3ee11276a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..88b16635d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..9971bced7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..8afd9e40a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..85c28b6c8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..e8af45bb8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..7717dd21f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..6c953896e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..825b4476d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..1272b12ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..2c8fc1311 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f3c8a279f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..97955ac4c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..4941d0f24 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..9c8795cbe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..848aa5a08 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..8554c6d68 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..c2731224f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..60331cebe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..c9b55ab0e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..398820d89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..3dd2d547c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..fe0620085 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..a67503d2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..507eee32b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..06074e420 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..05a234c72 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..33520690e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..3c83a5d45 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..592e3de92 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..1284ca90a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..0479d1a06 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..8854e6396 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..1c25cd2d7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..13f927e21 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..8d6b3c9af --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..5abc28ce9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d369edd22 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..59111b2c8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..5fb4f5095 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..98f4d2293 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..27507143d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..d8ea1385e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..a28110d56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0abaf1b7b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..ebd5436f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..25a4473a0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..c2a3842f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..f69a67c5b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..6d7e6ef17 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..38b5cfac8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..9d161984d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..9a9c606bf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..859973b52 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..806629d76 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..7488db300 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..c6b8ddc0a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..eb8bc92a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..685405d92 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..40cc2325b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..93087a05a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..23125279d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..171009604 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..1490117c0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..fc534a9a8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..401cc1464 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..b7d1359de --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..2d94c3b3f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0f4ee4276 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..52f4a1c49 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..d5f25ee2a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..0283fd8da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..869f91924 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..3c10251f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..73985e8ec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..9a7ea3ed2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..dc6db5368 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..0ee9510b9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..6861d19af --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..0238f6c93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt @@ -0,0 +1,145 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..52f7a33c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..8ceec6954 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt @@ -0,0 +1,155 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..084d3ac3d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f89494e57 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..3f587d1f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..cc0f9ed9d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..77266d93c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..beae342f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..0575bed67 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..36d8b3a58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a3a83a353 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..21aaba3c2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c21c615b2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..f043e3fd0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..8917fc7ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..45e111e68 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..a2f43a456 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..9ad7cdfdb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..bbdbae006 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..d6d0ae9ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..a8725656a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..5925895df --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..7bb7b3009 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..eb0b9ab49 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..04d0406e6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..3fdda9cce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..7d9c12c06 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..11c0d87df --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..662e311b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..87e8e27e9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..cf842d0ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..65c1caded --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..257af2d9f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d7eef46f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a7fc04459 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..220ce8c14 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..e6458b418 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..db1cdf474 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..73a661a22 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..99e5a2d94 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..f1f7dcdbe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..c32d605dc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..8c80d147a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..530fe35b7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..ae75d9ec5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b016b0785 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..07c1e9e47 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..18b6ec7f2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..a7fa3ad99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..a6f3feb64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..5de8211b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..634ddcb1a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ebeae45da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..50d49a9fa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..340d6fe8f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..735f180b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4d254c26f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..5873be48d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..ffde64591 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..f252ddcd1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..64506a765 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..7d8839951 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..163dbd841 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..5e3424a62 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..936523ac5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..7bbe0c166 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..46762b4f2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..00a33aaf8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..64557cefc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b73f5d29a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..b50eddc31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..03327cec3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..42aefae26 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..ab30ed5d0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c9d3cb337 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..e1924cb54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..d3ed07150 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..db811023f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..9ccd36e37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..bfcdbdc65 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a8664e59f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..8867bad63 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..7d40c38ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..a7552d21c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,164 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..f8aef1730 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,164 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..690286630 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..8fb6c4e4b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,180 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..a48d9fc5d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,180 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..19355a9b7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..baa4b1fc8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..8a2c59e11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..99281be52 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..df23ecb71 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt @@ -0,0 +1,169 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..670eb0934 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..4d008c0a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..eb78a909e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..21b391fb9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..463572661 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..0512da03c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..a5c84d000 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c510138aa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..7b11ecbc4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..ff5b17479 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..91ddf1698 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5051c6150 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..f67d13721 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..f935efe07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..3f60a7645 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..9e717ee91 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..11bd8e0d9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..9469ac8d0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..e1d7cc3ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..e84440901 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..40b90d254 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..69b495e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..d0484d31a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..4e7eabcb7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..b52ee1b64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..0570e7f9e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..c9153d6f4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..6f34ff803 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..0741749dd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..de5416a37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..e77078881 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..2c23fa4a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..cf3b8f92c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5a149d019 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..c535511a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..7fceabbcd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..b80fbbe06 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..b3836b7f4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..32e781126 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..780a17158 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..dc4ca2ba4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..5e0612df0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..2326fec64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..a59540425 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..80b182278 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..76b51bc12 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..f25b6d0d7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..2fabf6ec3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..d50562489 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..443dcf3ba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..6a4682b1e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..b8b4ec715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..33c007457 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..544aca9b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..13e33856a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..2736c805d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..67fdc8a22 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..08d839444 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..88c1fced6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..20ffb058b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..fa37927fd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..a52b01b58 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..cb8757bb8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..da5ba8ad0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..0ef09c5a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..b0609248e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..05e4c1d05 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..b3235218a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..9f3f52160 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..0637c8e60 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..58a185a42 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..3975bd078 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..a715a7144 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..1d07256ac --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a6802c08a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..96baacd4b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..3b11dcec0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..5f65bed3d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..707b07ae7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..41003afe8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..78ef55c9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..0f346a9e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..253b6bc1e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..0faa1a514 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..9fc762772 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..a9984641e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..7ecf175f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..a5c972fdc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..5f33b8a5b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..a0f6dd6b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..0026f9ab5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..f82e44dc2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..5b4bc511c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..4200d2be2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..bfc496515 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..9e5aa01e5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..6eaf84341 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..bb3f5e152 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..31fd49d42 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..f4cfe82a2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..682c30132 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..f3bdb9fd0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..b2a48d265 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..136994015 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..1cb9c7fe4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..0fd5a829b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..f49339e9b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..46ab7dd26 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..58428a273 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..7b227699c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..9b960a327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..3ec1879f2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..4f6ffcaef --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..2cb44080d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..518bb6214 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..530792fbb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..32f4d89a7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..5ed195a96 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..dcd37dcbe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..593d2953b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..843d41f35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d99ee9f12 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..e38673bc5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..ea5be926e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..8fc1ed1e0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..9afadfd66 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..1517502bc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..b52ef8fd4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..1c0f55a7d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..42014eabd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..2008244ce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..a47eff415 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..0e2732afd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..3717a90cb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..ecdaa9e39 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..4b9b0f6c7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..9acc1481d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..3c8ab3e2f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c56a9a67a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..09a56302c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..e20c18bba --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..213b781dd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..fb4207785 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..131d69e89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..22d8742b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..4f41b2a34 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..a67ace06f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..ecf396de6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..5422fccb6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..9d69e5796 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..2c371c62f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..ee1236431 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..17a5e4bfa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..00e856559 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..7cf1a2dab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..ebcc30d8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..f6011a30b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..f75315a9c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..bf795d05c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..3f679bdd7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..d7ae24bee --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..bb602088c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..b31cd934a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..702a14fc2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..7cd468e0b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..895fcdced --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..c9669fe9d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..828630bad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..831970829 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..60546f0e4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..4615aa1e6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..6b23a2566 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c583bf297 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..5497fb60d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,129 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..f48e9f6d7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..d678d9d96 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..27001c95e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..a4925f45b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..1bcb34dec --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..01b6f4f38 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..5c5f1f2c5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..d66339894 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..91f9c9590 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..5991b4275 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..d6dbd113e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..b846c8584 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..87be310d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..053251f0b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ec97309e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..f1090968b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..94ecd3dd1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..860d11d16 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..df51aa2d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d8a5c6692 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..46b12c670 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..7612bcd89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..653f68548 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..c2c4a296e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..3095448e4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..fb8614773 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..dd6a5b2d9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..33f297a6b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..c99c39b37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..7401046fe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..4a3ccb0a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..860616ee0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..78dd6de28 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..aa5f92335 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..e3440de53 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..35bdbbfd8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..79d3bddfd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..de2fefd8b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..e240cad6d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..ca9d169e9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..ec8a5819e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..93362714b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,102 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..29dbc8350 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..d1ee19da1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..e4dddd8bc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..9c1b9888c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..900772d34 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..d01d1f1bb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..81d79c37c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..6458fb752 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..a35106bda --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..18657f8db --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..66675bbeb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..5861025d0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..d69f00155 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..87c10ef89 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..c350aca6b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..e815662a0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..ba4ad5cfa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..54d8fd55c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..c53bdacbe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..1da29732f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..17658fee7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..27c228fce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..33fd76a2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..5973a811e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..8293a9b69 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..f9fc3a98c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..992e03701 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..12223faf9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..b4f807376 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..186f3dd01 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..29b35be43 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..08a3d45ce --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..b19cb0067 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5657ffacd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..e360395f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..56a4a03f7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..1ce4b2b03 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..2752fad2d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..8790eda6f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..b8979c0b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..4d9565758 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..f3d26701f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..ee737930b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..b531a492b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..05f0eda56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..af214684a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..7b31167ea --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..8e4f27bd8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,123 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..34c2a6229 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..86e2dc23e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..e92132df7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..009048bd9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..faaec318a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..5daa4f3b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..d53e4ca2d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..210035038 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..576d03e5a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..1775d37b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..41c86271e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..3cc8744f9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..bb7d4191e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..481431824 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..6787f464b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..def7b7ff4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..244098a07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..5f477a859 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..1b47d2cdc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..4b744040c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..f7ea38f7c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..9e307a24e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..64796958b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..cbbe29499 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..0dbb0c8fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..c96e15c39 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..1e7709545 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..9460bb27b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..b5165576b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..279037442 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..bf3f59d14 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..782c38adf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..90e4680a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..9e4678ea7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..1dc3712c8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..ed7bae957 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..735b48c9d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..bc1630e85 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..eb5c805fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..16ac1095b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..5ba5e3bbf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..1cfa95d85 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..208ec93c3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..8f185a4f3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..fe284d007 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..1a46b1ea2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..3745d9798 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..c47524526 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,116 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..149b45a2e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..a97e183fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..ceb58b565 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..6b44762bc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..c883b9be5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..7fa6b51fb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..ff76f547c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..e51eafe88 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,125 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..47c826ce2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..994f1ec31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..1ac0d5121 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..76822e596 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..a7eb745c4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..519f9aa82 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..6e4bf7b93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..670bd147a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt @@ -0,0 +1,122 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..b593cf637 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..5e33639dc --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..356154d78 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..b86125afd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..ca80b62b6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..f6d2fe3d0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..d58e49e2a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..9056b5935 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..4fe7970b7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..21b1e2184 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..8a3737cb5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..ad21ccf06 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..29e1d7b7c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..57961b962 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..0b9436d70 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..d61b7fbe2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,96 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..468548353 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..5c90fb22e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,97 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..f30324371 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..9bb26ff98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..f8b797795 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..7f6dcc442 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..55e959b56 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..088047efe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt @@ -0,0 +1,104 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..31b378a2a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..d61090972 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..ff1f2bcfa --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..e428caf34 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..552339ad5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..71d793ab8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..45bbc173a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..00d558c29 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..f7aa6b88a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..e85034bb7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..30c7b6e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..7e4555a75 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..25ee30f9e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..2b07a0f95 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,140 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..4a2d06fe7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..f206a3939 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..86deeb44d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..def904cb4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..5d04a3df8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..e9267cb05 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..7b65964a4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..885d7aca0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..cf5d603df --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..53e19cbac --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt @@ -0,0 +1,142 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..0ffdbf6e8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..f51444ab3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..bb46a843a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..4e5a7881e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..adb0efa71 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d210adb0d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..e1da0f039 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..c602db1c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..2eb0b902b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..5405ca9e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..eaffadd51 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..02364d284 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..ac15b8ad9 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..391dd15b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..f0573869f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..6a54390d3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..2ccf8ab8b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..4db8cff26 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..d6e8df674 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..e2f3c748f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..43c277ec4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..19e583761 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..fbd695fd5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..a0b5e9259 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..24f00de86 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..fce430505 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt new file mode 100644 index 000000000..13c35649c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt new file mode 100644 index 000000000..844aae323 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt new file mode 100644 index 000000000..1b1a7571e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt new file mode 100644 index 000000000..d71eddf41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt new file mode 100644 index 000000000..50dd4997e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt new file mode 100644 index 000000000..0f5a4c6b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt new file mode 100644 index 000000000..989973936 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt new file mode 100644 index 000000000..aa4e9b886 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt new file mode 100644 index 000000000..9608d512b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt new file mode 100644 index 000000000..b5e7ea476 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt new file mode 100644 index 000000000..764c960db --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt new file mode 100644 index 000000000..05431e594 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt new file mode 100644 index 000000000..ab5f9a4b3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt new file mode 100644 index 000000000..7d3108bd5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt @@ -0,0 +1,118 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt new file mode 100644 index 000000000..83ef853fe --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt new file mode 100644 index 000000000..398bb92af --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt @@ -0,0 +1,119 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt new file mode 100644 index 000000000..889795c39 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt new file mode 100644 index 000000000..e3fa6b90f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt new file mode 100644 index 000000000..338323c10 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt new file mode 100644 index 000000000..41754a740 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt new file mode 100644 index 000000000..8200d519e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt new file mode 100644 index 000000000..f84353ae2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt new file mode 100644 index 000000000..519454c49 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt new file mode 100644 index 000000000..939bef016 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt @@ -0,0 +1,124 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/StronglyTypedIdGeneratorTests.cs b/test/StronglyTypedIds.Tests/StronglyTypedIdGeneratorTests.cs index db399a465..287e7ed13 100644 --- a/test/StronglyTypedIds.Tests/StronglyTypedIdGeneratorTests.cs +++ b/test/StronglyTypedIds.Tests/StronglyTypedIdGeneratorTests.cs @@ -224,6 +224,7 @@ public static string ToArgument(StronglyTypedIdConverter converter) => StronglyTypedIdConverter.NewtonsoftJson => "StronglyTypedIdConverter.NewtonsoftJson", StronglyTypedIdConverter.SystemTextJson => "StronglyTypedIdConverter.SystemTextJson", StronglyTypedIdConverter.TypeConverter => "StronglyTypedIdConverter.TypeConverter", + StronglyTypedIdConverter.SwaggerSchemaFilter => "StronglyTypedIdConverter.SwaggerSchemaFilter", _ when converter.HasFlag(StronglyTypedIdConverter.NewtonsoftJson) && converter.HasFlag(StronglyTypedIdConverter.SystemTextJson) => "StronglyTypedIdConverter.NewtonsoftJson | StronglyTypedIdConverter.SystemTextJson", From b48da5e583331bb2d116438254f9f2c9e505603a Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 16:36:21 +0300 Subject: [PATCH 02/37] Tests --- StronglyTypedId.sln | 30 ++- .../StronglyTypedIds.IntegrationTests.csproj | 3 +- ...s.Nuget.Attributes.IntegrationTests.csproj | 6 +- ...nglyTypedIds.Nuget.IntegrationTests.csproj | 6 +- ...atesFullIdCorrectly_type=Guid.verified.txt | 14 ++ ...ratesFullIdCorrectly_type=Int.verified.txt | 14 ++ ...atesFullIdCorrectly_type=Long.verified.txt | 14 ++ ...rrectly_type=MassTransitNewId.verified.txt | 14 ++ ...Correctly_type=NullableString.verified.txt | 15 ++ ...esFullIdCorrectly_type=String.verified.txt | 15 ++ ...ngType=Guid_implementations=0.verified.txt | 92 --------- ...ngType=Guid_implementations=2.verified.txt | 92 --------- ...ngType=Guid_implementations=4.verified.txt | 93 --------- ...ngType=Guid_implementations=6.verified.txt | 93 --------- ...ingType=Int_implementations=0.verified.txt | 92 --------- ...ingType=Int_implementations=2.verified.txt | 92 --------- ...ingType=Int_implementations=4.verified.txt | 93 --------- ...ingType=Int_implementations=6.verified.txt | 93 --------- ...ngType=Long_implementations=0.verified.txt | 93 --------- ...ngType=Long_implementations=2.verified.txt | 93 --------- ...ngType=Long_implementations=4.verified.txt | 94 --------- ...ngType=Long_implementations=6.verified.txt | 94 --------- ...ransitNewId_implementations=0.verified.txt | 92 --------- ...ransitNewId_implementations=2.verified.txt | 92 --------- ...ransitNewId_implementations=4.verified.txt | 93 --------- ...ransitNewId_implementations=6.verified.txt | 93 --------- ...lableString_implementations=0.verified.txt | 108 ---------- ...lableString_implementations=2.verified.txt | 108 ---------- ...lableString_implementations=4.verified.txt | 118 ----------- ...lableString_implementations=6.verified.txt | 118 ----------- ...Type=String_implementations=0.verified.txt | 99 --------- ...Type=String_implementations=2.verified.txt | 99 --------- ...Type=String_implementations=4.verified.txt | 109 ---------- ...Type=String_implementations=6.verified.txt | 109 ---------- ...ngType=Guid_implementations=0.verified.txt | 134 ------------ ...ngType=Guid_implementations=2.verified.txt | 134 ------------ ...ngType=Guid_implementations=4.verified.txt | 135 ------------ ...ngType=Guid_implementations=6.verified.txt | 135 ------------ ...ingType=Int_implementations=0.verified.txt | 134 ------------ ...ingType=Int_implementations=2.verified.txt | 134 ------------ ...ingType=Int_implementations=4.verified.txt | 135 ------------ ...ingType=Int_implementations=6.verified.txt | 135 ------------ ...ngType=Long_implementations=0.verified.txt | 137 ------------- ...ngType=Long_implementations=2.verified.txt | 137 ------------- ...ngType=Long_implementations=4.verified.txt | 138 ------------- ...ngType=Long_implementations=6.verified.txt | 138 ------------- ...ransitNewId_implementations=0.verified.txt | 142 ------------- ...ransitNewId_implementations=2.verified.txt | 142 ------------- ...ransitNewId_implementations=4.verified.txt | 143 ------------- ...ransitNewId_implementations=6.verified.txt | 143 ------------- ...lableString_implementations=0.verified.txt | 151 -------------- ...lableString_implementations=2.verified.txt | 151 -------------- ...lableString_implementations=4.verified.txt | 161 --------------- ...lableString_implementations=6.verified.txt | 161 --------------- ...Type=String_implementations=0.verified.txt | 137 ------------- ...Type=String_implementations=2.verified.txt | 137 ------------- ...Type=String_implementations=4.verified.txt | 147 ------------- ...Type=String_implementations=6.verified.txt | 147 ------------- ...ngType=Guid_implementations=0.verified.txt | 85 -------- ...ngType=Guid_implementations=2.verified.txt | 85 -------- ...ngType=Guid_implementations=4.verified.txt | 86 -------- ...ngType=Guid_implementations=6.verified.txt | 86 -------- ...ingType=Int_implementations=0.verified.txt | 85 -------- ...ingType=Int_implementations=2.verified.txt | 85 -------- ...ingType=Int_implementations=4.verified.txt | 86 -------- ...ingType=Int_implementations=6.verified.txt | 86 -------- ...ngType=Long_implementations=0.verified.txt | 86 -------- ...ngType=Long_implementations=2.verified.txt | 86 -------- ...ngType=Long_implementations=4.verified.txt | 87 -------- ...ngType=Long_implementations=6.verified.txt | 87 -------- ...ransitNewId_implementations=0.verified.txt | 85 -------- ...ransitNewId_implementations=2.verified.txt | 85 -------- ...ransitNewId_implementations=4.verified.txt | 86 -------- ...ransitNewId_implementations=6.verified.txt | 86 -------- ...lableString_implementations=0.verified.txt | 102 --------- ...lableString_implementations=2.verified.txt | 102 --------- ...lableString_implementations=4.verified.txt | 112 ---------- ...lableString_implementations=6.verified.txt | 112 ---------- ...Type=String_implementations=0.verified.txt | 93 --------- ...Type=String_implementations=2.verified.txt | 93 --------- ...Type=String_implementations=4.verified.txt | 103 ---------- ...Type=String_implementations=6.verified.txt | 103 ---------- ...ngType=Guid_implementations=0.verified.txt | 127 ------------ ...ngType=Guid_implementations=2.verified.txt | 127 ------------ ...ngType=Guid_implementations=4.verified.txt | 128 ------------ ...ngType=Guid_implementations=6.verified.txt | 128 ------------ ...ingType=Int_implementations=0.verified.txt | 127 ------------ ...ingType=Int_implementations=2.verified.txt | 127 ------------ ...ingType=Int_implementations=4.verified.txt | 128 ------------ ...ingType=Int_implementations=6.verified.txt | 128 ------------ ...ngType=Long_implementations=0.verified.txt | 130 ------------ ...ngType=Long_implementations=2.verified.txt | 130 ------------ ...ngType=Long_implementations=4.verified.txt | 131 ------------ ...ngType=Long_implementations=6.verified.txt | 131 ------------ ...ransitNewId_implementations=0.verified.txt | 135 ------------ ...ransitNewId_implementations=2.verified.txt | 135 ------------ ...ransitNewId_implementations=4.verified.txt | 136 ------------ ...ransitNewId_implementations=6.verified.txt | 136 ------------ ...lableString_implementations=0.verified.txt | 145 ------------- ...lableString_implementations=2.verified.txt | 145 ------------- ...lableString_implementations=4.verified.txt | 155 -------------- ...lableString_implementations=6.verified.txt | 155 -------------- ...Type=String_implementations=0.verified.txt | 131 ------------ ...Type=String_implementations=2.verified.txt | 131 ------------ ...Type=String_implementations=4.verified.txt | 141 ------------- ...Type=String_implementations=6.verified.txt | 141 ------------- ...ngType=Guid_implementations=0.verified.txt | 106 ---------- ...ngType=Guid_implementations=2.verified.txt | 106 ---------- ...ngType=Guid_implementations=4.verified.txt | 107 ---------- ...ngType=Guid_implementations=6.verified.txt | 107 ---------- ...ingType=Int_implementations=0.verified.txt | 106 ---------- ...ingType=Int_implementations=2.verified.txt | 106 ---------- ...ingType=Int_implementations=4.verified.txt | 107 ---------- ...ingType=Int_implementations=6.verified.txt | 107 ---------- ...ngType=Long_implementations=0.verified.txt | 107 ---------- ...ngType=Long_implementations=2.verified.txt | 107 ---------- ...ngType=Long_implementations=4.verified.txt | 108 ---------- ...ngType=Long_implementations=6.verified.txt | 108 ---------- ...ransitNewId_implementations=0.verified.txt | 106 ---------- ...ransitNewId_implementations=2.verified.txt | 106 ---------- ...ransitNewId_implementations=4.verified.txt | 107 ---------- ...ransitNewId_implementations=6.verified.txt | 107 ---------- ...lableString_implementations=0.verified.txt | 129 ------------ ...lableString_implementations=2.verified.txt | 129 ------------ ...lableString_implementations=4.verified.txt | 139 ------------- ...lableString_implementations=6.verified.txt | 139 ------------- ...Type=String_implementations=0.verified.txt | 113 ---------- ...Type=String_implementations=2.verified.txt | 113 ---------- ...Type=String_implementations=4.verified.txt | 123 ----------- ...Type=String_implementations=6.verified.txt | 123 ----------- ...ngType=Guid_implementations=0.verified.txt | 148 -------------- ...ngType=Guid_implementations=2.verified.txt | 148 -------------- ...ngType=Guid_implementations=4.verified.txt | 149 -------------- ...ngType=Guid_implementations=6.verified.txt | 149 -------------- ...ingType=Int_implementations=0.verified.txt | 148 -------------- ...ingType=Int_implementations=2.verified.txt | 148 -------------- ...ingType=Int_implementations=4.verified.txt | 149 -------------- ...ingType=Int_implementations=6.verified.txt | 149 -------------- ...ngType=Long_implementations=0.verified.txt | 151 -------------- ...ngType=Long_implementations=2.verified.txt | 151 -------------- ...ngType=Long_implementations=4.verified.txt | 152 -------------- ...ngType=Long_implementations=6.verified.txt | 152 -------------- ...ransitNewId_implementations=0.verified.txt | 156 -------------- ...ransitNewId_implementations=2.verified.txt | 156 -------------- ...ransitNewId_implementations=4.verified.txt | 157 -------------- ...ransitNewId_implementations=6.verified.txt | 157 -------------- ...lableString_implementations=0.verified.txt | 172 ---------------- ...lableString_implementations=2.verified.txt | 172 ---------------- ...lableString_implementations=4.verified.txt | 182 ----------------- ...lableString_implementations=6.verified.txt | 182 ----------------- ...Type=String_implementations=0.verified.txt | 151 -------------- ...Type=String_implementations=2.verified.txt | 151 -------------- ...Type=String_implementations=4.verified.txt | 161 --------------- ...Type=String_implementations=6.verified.txt | 161 --------------- ...ngType=Guid_implementations=0.verified.txt | 82 -------- ...ngType=Guid_implementations=2.verified.txt | 82 -------- ...ngType=Guid_implementations=4.verified.txt | 83 -------- ...ngType=Guid_implementations=6.verified.txt | 83 -------- ...ingType=Int_implementations=0.verified.txt | 82 -------- ...ingType=Int_implementations=2.verified.txt | 82 -------- ...ingType=Int_implementations=4.verified.txt | 83 -------- ...ingType=Int_implementations=6.verified.txt | 83 -------- ...ngType=Long_implementations=0.verified.txt | 83 -------- ...ngType=Long_implementations=2.verified.txt | 83 -------- ...ngType=Long_implementations=4.verified.txt | 84 -------- ...ngType=Long_implementations=6.verified.txt | 84 -------- ...ransitNewId_implementations=0.verified.txt | 82 -------- ...ransitNewId_implementations=2.verified.txt | 82 -------- ...ransitNewId_implementations=4.verified.txt | 83 -------- ...ransitNewId_implementations=6.verified.txt | 83 -------- ...lableString_implementations=0.verified.txt | 92 --------- ...lableString_implementations=2.verified.txt | 92 --------- ...lableString_implementations=4.verified.txt | 102 --------- ...lableString_implementations=6.verified.txt | 102 --------- ...Type=String_implementations=0.verified.txt | 90 -------- ...Type=String_implementations=2.verified.txt | 90 -------- ...Type=String_implementations=4.verified.txt | 100 --------- ...Type=String_implementations=6.verified.txt | 100 --------- ...ngType=Guid_implementations=0.verified.txt | 124 ----------- ...ngType=Guid_implementations=2.verified.txt | 124 ----------- ...ngType=Guid_implementations=4.verified.txt | 125 ------------ ...ngType=Guid_implementations=6.verified.txt | 125 ------------ ...ingType=Int_implementations=0.verified.txt | 124 ----------- ...ingType=Int_implementations=2.verified.txt | 124 ----------- ...ingType=Int_implementations=4.verified.txt | 125 ------------ ...ingType=Int_implementations=6.verified.txt | 125 ------------ ...ngType=Long_implementations=0.verified.txt | 127 ------------ ...ngType=Long_implementations=2.verified.txt | 127 ------------ ...ngType=Long_implementations=4.verified.txt | 128 ------------ ...ngType=Long_implementations=6.verified.txt | 128 ------------ ...ransitNewId_implementations=0.verified.txt | 132 ------------ ...ransitNewId_implementations=2.verified.txt | 132 ------------ ...ransitNewId_implementations=4.verified.txt | 133 ------------ ...ransitNewId_implementations=6.verified.txt | 133 ------------ ...lableString_implementations=0.verified.txt | 135 ------------ ...lableString_implementations=2.verified.txt | 135 ------------ ...lableString_implementations=4.verified.txt | 145 ------------- ...lableString_implementations=6.verified.txt | 145 ------------- ...Type=String_implementations=0.verified.txt | 128 ------------ ...Type=String_implementations=2.verified.txt | 128 ------------ ...Type=String_implementations=4.verified.txt | 138 ------------- ...Type=String_implementations=6.verified.txt | 138 ------------- ...ngType=Guid_implementations=0.verified.txt | 103 ---------- ...ngType=Guid_implementations=2.verified.txt | 103 ---------- ...ngType=Guid_implementations=4.verified.txt | 104 ---------- ...ngType=Guid_implementations=6.verified.txt | 104 ---------- ...ingType=Int_implementations=0.verified.txt | 103 ---------- ...ingType=Int_implementations=2.verified.txt | 103 ---------- ...ingType=Int_implementations=4.verified.txt | 104 ---------- ...ingType=Int_implementations=6.verified.txt | 104 ---------- ...ngType=Long_implementations=0.verified.txt | 104 ---------- ...ngType=Long_implementations=2.verified.txt | 104 ---------- ...ngType=Long_implementations=4.verified.txt | 105 ---------- ...ngType=Long_implementations=6.verified.txt | 105 ---------- ...ransitNewId_implementations=0.verified.txt | 103 ---------- ...ransitNewId_implementations=2.verified.txt | 103 ---------- ...ransitNewId_implementations=4.verified.txt | 104 ---------- ...ransitNewId_implementations=6.verified.txt | 104 ---------- ...lableString_implementations=0.verified.txt | 119 ----------- ...lableString_implementations=2.verified.txt | 119 ----------- ...lableString_implementations=4.verified.txt | 129 ------------ ...lableString_implementations=6.verified.txt | 129 ------------ ...Type=String_implementations=0.verified.txt | 110 ---------- ...Type=String_implementations=2.verified.txt | 110 ---------- ...Type=String_implementations=4.verified.txt | 120 ----------- ...Type=String_implementations=6.verified.txt | 120 ----------- ...ngType=Guid_implementations=0.verified.txt | 145 ------------- ...ngType=Guid_implementations=2.verified.txt | 145 ------------- ...ngType=Guid_implementations=4.verified.txt | 146 ------------- ...ngType=Guid_implementations=6.verified.txt | 146 ------------- ...ingType=Int_implementations=0.verified.txt | 145 ------------- ...ingType=Int_implementations=2.verified.txt | 145 ------------- ...ingType=Int_implementations=4.verified.txt | 146 ------------- ...ingType=Int_implementations=6.verified.txt | 146 ------------- ...ngType=Long_implementations=0.verified.txt | 148 -------------- ...ngType=Long_implementations=2.verified.txt | 148 -------------- ...ngType=Long_implementations=4.verified.txt | 149 -------------- ...ngType=Long_implementations=6.verified.txt | 149 -------------- ...ransitNewId_implementations=0.verified.txt | 153 -------------- ...ransitNewId_implementations=2.verified.txt | 153 -------------- ...ransitNewId_implementations=4.verified.txt | 154 -------------- ...ransitNewId_implementations=6.verified.txt | 154 -------------- ...lableString_implementations=0.verified.txt | 162 --------------- ...lableString_implementations=2.verified.txt | 162 --------------- ...lableString_implementations=4.verified.txt | 172 ---------------- ...lableString_implementations=6.verified.txt | 172 ---------------- ...Type=String_implementations=0.verified.txt | 148 -------------- ...Type=String_implementations=2.verified.txt | 148 -------------- ...Type=String_implementations=4.verified.txt | 158 -------------- ...Type=String_implementations=6.verified.txt | 158 -------------- ...ngType=Guid_implementations=0.verified.txt | 96 --------- ...ngType=Guid_implementations=2.verified.txt | 96 --------- ...ngType=Guid_implementations=4.verified.txt | 97 --------- ...ngType=Guid_implementations=6.verified.txt | 97 --------- ...ingType=Int_implementations=0.verified.txt | 96 --------- ...ingType=Int_implementations=2.verified.txt | 96 --------- ...ingType=Int_implementations=4.verified.txt | 97 --------- ...ingType=Int_implementations=6.verified.txt | 97 --------- ...ngType=Long_implementations=0.verified.txt | 97 --------- ...ngType=Long_implementations=2.verified.txt | 97 --------- ...ngType=Long_implementations=4.verified.txt | 98 --------- ...ngType=Long_implementations=6.verified.txt | 98 --------- ...ransitNewId_implementations=0.verified.txt | 96 --------- ...ransitNewId_implementations=2.verified.txt | 96 --------- ...ransitNewId_implementations=4.verified.txt | 97 --------- ...ransitNewId_implementations=6.verified.txt | 97 --------- ...lableString_implementations=0.verified.txt | 113 ---------- ...lableString_implementations=2.verified.txt | 113 ---------- ...lableString_implementations=4.verified.txt | 123 ----------- ...lableString_implementations=6.verified.txt | 123 ----------- ...Type=String_implementations=0.verified.txt | 104 ---------- ...Type=String_implementations=2.verified.txt | 104 ---------- ...Type=String_implementations=4.verified.txt | 114 ----------- ...Type=String_implementations=6.verified.txt | 114 ----------- ...ngType=Guid_implementations=0.verified.txt | 138 ------------- ...ngType=Guid_implementations=2.verified.txt | 138 ------------- ...ngType=Guid_implementations=4.verified.txt | 139 ------------- ...ngType=Guid_implementations=6.verified.txt | 139 ------------- ...ingType=Int_implementations=0.verified.txt | 138 ------------- ...ingType=Int_implementations=2.verified.txt | 138 ------------- ...ingType=Int_implementations=4.verified.txt | 139 ------------- ...ingType=Int_implementations=6.verified.txt | 139 ------------- ...ngType=Long_implementations=0.verified.txt | 141 ------------- ...ngType=Long_implementations=2.verified.txt | 141 ------------- ...ngType=Long_implementations=4.verified.txt | 142 ------------- ...ngType=Long_implementations=6.verified.txt | 142 ------------- ...ransitNewId_implementations=0.verified.txt | 146 ------------- ...ransitNewId_implementations=2.verified.txt | 146 ------------- ...ransitNewId_implementations=4.verified.txt | 147 ------------- ...ransitNewId_implementations=6.verified.txt | 147 ------------- ...lableString_implementations=0.verified.txt | 156 -------------- ...lableString_implementations=2.verified.txt | 156 -------------- ...lableString_implementations=4.verified.txt | 166 --------------- ...lableString_implementations=6.verified.txt | 166 --------------- ...Type=String_implementations=0.verified.txt | 142 ------------- ...Type=String_implementations=2.verified.txt | 142 ------------- ...Type=String_implementations=4.verified.txt | 152 -------------- ...Type=String_implementations=6.verified.txt | 152 -------------- ...ngType=Guid_implementations=0.verified.txt | 117 ----------- ...ngType=Guid_implementations=2.verified.txt | 117 ----------- ...ngType=Guid_implementations=4.verified.txt | 118 ----------- ...ngType=Guid_implementations=6.verified.txt | 118 ----------- ...ingType=Int_implementations=0.verified.txt | 117 ----------- ...ingType=Int_implementations=2.verified.txt | 117 ----------- ...ingType=Int_implementations=4.verified.txt | 118 ----------- ...ingType=Int_implementations=6.verified.txt | 118 ----------- ...ngType=Long_implementations=0.verified.txt | 118 ----------- ...ngType=Long_implementations=2.verified.txt | 118 ----------- ...ngType=Long_implementations=4.verified.txt | 119 ----------- ...ngType=Long_implementations=6.verified.txt | 119 ----------- ...ransitNewId_implementations=0.verified.txt | 117 ----------- ...ransitNewId_implementations=2.verified.txt | 117 ----------- ...ransitNewId_implementations=4.verified.txt | 118 ----------- ...ransitNewId_implementations=6.verified.txt | 118 ----------- ...lableString_implementations=0.verified.txt | 140 ------------- ...lableString_implementations=2.verified.txt | 140 ------------- ...lableString_implementations=4.verified.txt | 150 -------------- ...lableString_implementations=6.verified.txt | 150 -------------- ...Type=String_implementations=0.verified.txt | 124 ----------- ...Type=String_implementations=2.verified.txt | 124 ----------- ...Type=String_implementations=4.verified.txt | 134 ------------ ...Type=String_implementations=6.verified.txt | 134 ------------ ...ngType=Guid_implementations=0.verified.txt | 159 --------------- ...ngType=Guid_implementations=2.verified.txt | 159 --------------- ...ngType=Guid_implementations=4.verified.txt | 160 --------------- ...ngType=Guid_implementations=6.verified.txt | 160 --------------- ...ingType=Int_implementations=0.verified.txt | 159 --------------- ...ingType=Int_implementations=2.verified.txt | 159 --------------- ...ingType=Int_implementations=4.verified.txt | 160 --------------- ...ingType=Int_implementations=6.verified.txt | 160 --------------- ...ngType=Long_implementations=0.verified.txt | 162 --------------- ...ngType=Long_implementations=2.verified.txt | 162 --------------- ...ngType=Long_implementations=4.verified.txt | 163 --------------- ...ngType=Long_implementations=6.verified.txt | 163 --------------- ...ransitNewId_implementations=0.verified.txt | 167 --------------- ...ransitNewId_implementations=2.verified.txt | 167 --------------- ...ransitNewId_implementations=4.verified.txt | 168 --------------- ...ransitNewId_implementations=6.verified.txt | 168 --------------- ...lableString_implementations=0.verified.txt | 183 ----------------- ...lableString_implementations=2.verified.txt | 183 ----------------- ...lableString_implementations=4.verified.txt | 193 ------------------ ...lableString_implementations=6.verified.txt | 193 ------------------ ...Type=String_implementations=0.verified.txt | 162 --------------- ...Type=String_implementations=2.verified.txt | 162 --------------- ...Type=String_implementations=4.verified.txt | 172 ---------------- ...Type=String_implementations=6.verified.txt | 172 ---------------- ...ngType=Guid_implementations=0.verified.txt | 53 ----- ...ngType=Guid_implementations=2.verified.txt | 53 ----- ...ngType=Guid_implementations=4.verified.txt | 54 ----- ...ngType=Guid_implementations=6.verified.txt | 54 ----- ...ingType=Int_implementations=0.verified.txt | 52 ----- ...ingType=Int_implementations=2.verified.txt | 52 ----- ...ingType=Int_implementations=4.verified.txt | 53 ----- ...ingType=Int_implementations=6.verified.txt | 53 ----- ...ngType=Long_implementations=0.verified.txt | 52 ----- ...ngType=Long_implementations=2.verified.txt | 52 ----- ...ngType=Long_implementations=4.verified.txt | 53 ----- ...ngType=Long_implementations=6.verified.txt | 53 ----- ...ransitNewId_implementations=0.verified.txt | 53 ----- ...ransitNewId_implementations=2.verified.txt | 53 ----- ...ransitNewId_implementations=4.verified.txt | 54 ----- ...ransitNewId_implementations=6.verified.txt | 54 ----- ...lableString_implementations=0.verified.txt | 62 ------ ...lableString_implementations=2.verified.txt | 62 ------ ...lableString_implementations=4.verified.txt | 72 ------- ...lableString_implementations=6.verified.txt | 72 ------- ...Type=String_implementations=0.verified.txt | 62 ------ ...Type=String_implementations=2.verified.txt | 62 ------ ...Type=String_implementations=4.verified.txt | 72 ------- ...Type=String_implementations=6.verified.txt | 72 ------- ...ngType=Guid_implementations=0.verified.txt | 95 --------- ...ngType=Guid_implementations=2.verified.txt | 95 --------- ...ngType=Guid_implementations=4.verified.txt | 96 --------- ...ngType=Guid_implementations=6.verified.txt | 96 --------- ...ingType=Int_implementations=0.verified.txt | 94 --------- ...ingType=Int_implementations=2.verified.txt | 94 --------- ...ingType=Int_implementations=4.verified.txt | 95 --------- ...ingType=Int_implementations=6.verified.txt | 95 --------- ...ngType=Long_implementations=0.verified.txt | 96 --------- ...ngType=Long_implementations=2.verified.txt | 96 --------- ...ngType=Long_implementations=4.verified.txt | 97 --------- ...ngType=Long_implementations=6.verified.txt | 97 --------- ...ransitNewId_implementations=0.verified.txt | 103 ---------- ...ransitNewId_implementations=2.verified.txt | 103 ---------- ...ransitNewId_implementations=4.verified.txt | 104 ---------- ...ransitNewId_implementations=6.verified.txt | 104 ---------- ...lableString_implementations=0.verified.txt | 105 ---------- ...lableString_implementations=2.verified.txt | 105 ---------- ...lableString_implementations=4.verified.txt | 115 ----------- ...lableString_implementations=6.verified.txt | 115 ----------- ...Type=String_implementations=0.verified.txt | 100 --------- ...Type=String_implementations=2.verified.txt | 100 --------- ...Type=String_implementations=4.verified.txt | 110 ---------- ...Type=String_implementations=6.verified.txt | 110 ---------- ...ngType=Guid_implementations=0.verified.txt | 74 ------- ...ngType=Guid_implementations=2.verified.txt | 74 ------- ...ngType=Guid_implementations=4.verified.txt | 75 ------- ...ngType=Guid_implementations=6.verified.txt | 75 ------- ...ingType=Int_implementations=0.verified.txt | 73 ------- ...ingType=Int_implementations=2.verified.txt | 73 ------- ...ingType=Int_implementations=4.verified.txt | 74 ------- ...ingType=Int_implementations=6.verified.txt | 74 ------- ...ngType=Long_implementations=0.verified.txt | 73 ------- ...ngType=Long_implementations=2.verified.txt | 73 ------- ...ngType=Long_implementations=4.verified.txt | 74 ------- ...ngType=Long_implementations=6.verified.txt | 74 ------- ...ransitNewId_implementations=0.verified.txt | 74 ------- ...ransitNewId_implementations=2.verified.txt | 74 ------- ...ransitNewId_implementations=4.verified.txt | 75 ------- ...ransitNewId_implementations=6.verified.txt | 75 ------- ...lableString_implementations=0.verified.txt | 89 -------- ...lableString_implementations=2.verified.txt | 89 -------- ...lableString_implementations=4.verified.txt | 99 --------- ...lableString_implementations=6.verified.txt | 99 --------- ...Type=String_implementations=0.verified.txt | 82 -------- ...Type=String_implementations=2.verified.txt | 82 -------- ...Type=String_implementations=4.verified.txt | 92 --------- ...Type=String_implementations=6.verified.txt | 92 --------- ...ngType=Guid_implementations=0.verified.txt | 116 ----------- ...ngType=Guid_implementations=2.verified.txt | 116 ----------- ...ngType=Guid_implementations=4.verified.txt | 117 ----------- ...ngType=Guid_implementations=6.verified.txt | 117 ----------- ...ingType=Int_implementations=0.verified.txt | 115 ----------- ...ingType=Int_implementations=2.verified.txt | 115 ----------- ...ingType=Int_implementations=4.verified.txt | 116 ----------- ...ingType=Int_implementations=6.verified.txt | 116 ----------- ...ngType=Long_implementations=0.verified.txt | 117 ----------- ...ngType=Long_implementations=2.verified.txt | 117 ----------- ...ngType=Long_implementations=4.verified.txt | 118 ----------- ...ngType=Long_implementations=6.verified.txt | 118 ----------- ...ransitNewId_implementations=0.verified.txt | 124 ----------- ...ransitNewId_implementations=2.verified.txt | 124 ----------- ...ransitNewId_implementations=4.verified.txt | 125 ------------ ...ransitNewId_implementations=6.verified.txt | 125 ------------ ...lableString_implementations=0.verified.txt | 132 ------------ ...lableString_implementations=2.verified.txt | 132 ------------ ...lableString_implementations=4.verified.txt | 142 ------------- ...lableString_implementations=6.verified.txt | 142 ------------- ...Type=String_implementations=0.verified.txt | 120 ----------- ...Type=String_implementations=2.verified.txt | 120 ----------- ...Type=String_implementations=4.verified.txt | 130 ------------ ...Type=String_implementations=6.verified.txt | 130 ------------ ...ngType=Guid_implementations=0.verified.txt | 67 ------ ...ngType=Guid_implementations=2.verified.txt | 67 ------ ...ngType=Guid_implementations=4.verified.txt | 68 ------ ...ngType=Guid_implementations=6.verified.txt | 68 ------ ...ingType=Int_implementations=0.verified.txt | 66 ------ ...ingType=Int_implementations=2.verified.txt | 66 ------ ...ingType=Int_implementations=4.verified.txt | 67 ------ ...ingType=Int_implementations=6.verified.txt | 67 ------ ...ngType=Long_implementations=0.verified.txt | 66 ------ ...ngType=Long_implementations=2.verified.txt | 66 ------ ...ngType=Long_implementations=4.verified.txt | 67 ------ ...ngType=Long_implementations=6.verified.txt | 67 ------ ...ransitNewId_implementations=0.verified.txt | 67 ------ ...ransitNewId_implementations=2.verified.txt | 67 ------ ...ransitNewId_implementations=4.verified.txt | 68 ------ ...ransitNewId_implementations=6.verified.txt | 68 ------ ...lableString_implementations=0.verified.txt | 83 -------- ...lableString_implementations=2.verified.txt | 83 -------- ...lableString_implementations=4.verified.txt | 93 --------- ...lableString_implementations=6.verified.txt | 93 --------- ...Type=String_implementations=0.verified.txt | 76 ------- ...Type=String_implementations=2.verified.txt | 76 ------- ...Type=String_implementations=4.verified.txt | 86 -------- ...Type=String_implementations=6.verified.txt | 86 -------- ...ngType=Guid_implementations=0.verified.txt | 109 ---------- ...ngType=Guid_implementations=2.verified.txt | 109 ---------- ...ngType=Guid_implementations=4.verified.txt | 110 ---------- ...ngType=Guid_implementations=6.verified.txt | 110 ---------- ...ingType=Int_implementations=0.verified.txt | 108 ---------- ...ingType=Int_implementations=2.verified.txt | 108 ---------- ...ingType=Int_implementations=4.verified.txt | 109 ---------- ...ingType=Int_implementations=6.verified.txt | 109 ---------- ...ngType=Long_implementations=0.verified.txt | 110 ---------- ...ngType=Long_implementations=2.verified.txt | 110 ---------- ...ngType=Long_implementations=4.verified.txt | 111 ---------- ...ngType=Long_implementations=6.verified.txt | 111 ---------- ...ransitNewId_implementations=0.verified.txt | 117 ----------- ...ransitNewId_implementations=2.verified.txt | 117 ----------- ...ransitNewId_implementations=4.verified.txt | 118 ----------- ...ransitNewId_implementations=6.verified.txt | 118 ----------- ...lableString_implementations=0.verified.txt | 126 ------------ ...lableString_implementations=2.verified.txt | 126 ------------ ...lableString_implementations=4.verified.txt | 136 ------------ ...lableString_implementations=6.verified.txt | 136 ------------ ...Type=String_implementations=0.verified.txt | 114 ----------- ...Type=String_implementations=2.verified.txt | 114 ----------- ...Type=String_implementations=4.verified.txt | 124 ----------- ...Type=String_implementations=6.verified.txt | 124 ----------- ...ngType=Guid_implementations=0.verified.txt | 88 -------- ...ngType=Guid_implementations=2.verified.txt | 88 -------- ...ngType=Guid_implementations=4.verified.txt | 89 -------- ...ngType=Guid_implementations=6.verified.txt | 89 -------- ...ingType=Int_implementations=0.verified.txt | 87 -------- ...ingType=Int_implementations=2.verified.txt | 87 -------- ...ingType=Int_implementations=4.verified.txt | 88 -------- ...ingType=Int_implementations=6.verified.txt | 88 -------- ...ngType=Long_implementations=0.verified.txt | 87 -------- ...ngType=Long_implementations=2.verified.txt | 87 -------- ...ngType=Long_implementations=4.verified.txt | 88 -------- ...ngType=Long_implementations=6.verified.txt | 88 -------- ...ransitNewId_implementations=0.verified.txt | 88 -------- ...ransitNewId_implementations=2.verified.txt | 88 -------- ...ransitNewId_implementations=4.verified.txt | 89 -------- ...ransitNewId_implementations=6.verified.txt | 89 -------- ...lableString_implementations=0.verified.txt | 110 ---------- ...lableString_implementations=2.verified.txt | 110 ---------- ...lableString_implementations=4.verified.txt | 120 ----------- ...lableString_implementations=6.verified.txt | 120 ----------- ...Type=String_implementations=0.verified.txt | 96 --------- ...Type=String_implementations=2.verified.txt | 96 --------- ...Type=String_implementations=4.verified.txt | 106 ---------- ...Type=String_implementations=6.verified.txt | 106 ---------- ...ngType=Guid_implementations=0.verified.txt | 130 ------------ ...ngType=Guid_implementations=2.verified.txt | 130 ------------ ...ngType=Guid_implementations=4.verified.txt | 131 ------------ ...ngType=Guid_implementations=6.verified.txt | 131 ------------ ...ingType=Int_implementations=0.verified.txt | 129 ------------ ...ingType=Int_implementations=2.verified.txt | 129 ------------ ...ingType=Int_implementations=4.verified.txt | 130 ------------ ...ingType=Int_implementations=6.verified.txt | 130 ------------ ...ngType=Long_implementations=0.verified.txt | 131 ------------ ...ngType=Long_implementations=2.verified.txt | 131 ------------ ...ngType=Long_implementations=4.verified.txt | 132 ------------ ...ngType=Long_implementations=6.verified.txt | 132 ------------ ...ransitNewId_implementations=0.verified.txt | 138 ------------- ...ransitNewId_implementations=2.verified.txt | 138 ------------- ...ransitNewId_implementations=4.verified.txt | 139 ------------- ...ransitNewId_implementations=6.verified.txt | 139 ------------- ...lableString_implementations=0.verified.txt | 153 -------------- ...lableString_implementations=2.verified.txt | 153 -------------- ...lableString_implementations=4.verified.txt | 163 --------------- ...lableString_implementations=6.verified.txt | 163 --------------- ...Type=String_implementations=0.verified.txt | 134 ------------ ...Type=String_implementations=2.verified.txt | 134 ------------ ...Type=String_implementations=4.verified.txt | 144 ------------- ...Type=String_implementations=6.verified.txt | 144 ------------- ...ngType=Guid_implementations=0.verified.txt | 64 ------ ...ngType=Guid_implementations=2.verified.txt | 64 ------ ...ngType=Guid_implementations=4.verified.txt | 65 ------ ...ngType=Guid_implementations=6.verified.txt | 65 ------ ...ingType=Int_implementations=0.verified.txt | 63 ------ ...ingType=Int_implementations=2.verified.txt | 63 ------ ...ingType=Int_implementations=4.verified.txt | 64 ------ ...ingType=Int_implementations=6.verified.txt | 64 ------ ...ngType=Long_implementations=0.verified.txt | 63 ------ ...ngType=Long_implementations=2.verified.txt | 63 ------ ...ngType=Long_implementations=4.verified.txt | 64 ------ ...ngType=Long_implementations=6.verified.txt | 64 ------ ...ransitNewId_implementations=0.verified.txt | 64 ------ ...ransitNewId_implementations=2.verified.txt | 64 ------ ...ransitNewId_implementations=4.verified.txt | 65 ------ ...ransitNewId_implementations=6.verified.txt | 65 ------ ...lableString_implementations=0.verified.txt | 73 ------- ...lableString_implementations=2.verified.txt | 73 ------- ...lableString_implementations=4.verified.txt | 83 -------- ...lableString_implementations=6.verified.txt | 83 -------- ...Type=String_implementations=0.verified.txt | 73 ------- ...Type=String_implementations=2.verified.txt | 73 ------- ...Type=String_implementations=4.verified.txt | 83 -------- ...Type=String_implementations=6.verified.txt | 83 -------- ...ngType=Guid_implementations=0.verified.txt | 106 ---------- ...ngType=Guid_implementations=2.verified.txt | 106 ---------- ...ngType=Guid_implementations=4.verified.txt | 107 ---------- ...ngType=Guid_implementations=6.verified.txt | 107 ---------- ...ingType=Int_implementations=0.verified.txt | 105 ---------- ...ingType=Int_implementations=2.verified.txt | 105 ---------- ...ingType=Int_implementations=4.verified.txt | 106 ---------- ...ingType=Int_implementations=6.verified.txt | 106 ---------- ...ngType=Long_implementations=0.verified.txt | 107 ---------- ...ngType=Long_implementations=2.verified.txt | 107 ---------- ...ngType=Long_implementations=4.verified.txt | 108 ---------- ...ngType=Long_implementations=6.verified.txt | 108 ---------- ...ransitNewId_implementations=0.verified.txt | 114 ----------- ...ransitNewId_implementations=2.verified.txt | 114 ----------- ...ransitNewId_implementations=4.verified.txt | 115 ----------- ...ransitNewId_implementations=6.verified.txt | 115 ----------- ...lableString_implementations=0.verified.txt | 116 ----------- ...lableString_implementations=2.verified.txt | 116 ----------- ...lableString_implementations=4.verified.txt | 126 ------------ ...lableString_implementations=6.verified.txt | 126 ------------ ...Type=String_implementations=0.verified.txt | 111 ---------- ...Type=String_implementations=2.verified.txt | 111 ---------- ...Type=String_implementations=4.verified.txt | 121 ----------- ...Type=String_implementations=6.verified.txt | 121 ----------- ...ngType=Guid_implementations=0.verified.txt | 85 -------- ...ngType=Guid_implementations=2.verified.txt | 85 -------- ...ngType=Guid_implementations=4.verified.txt | 86 -------- ...ngType=Guid_implementations=6.verified.txt | 86 -------- ...ingType=Int_implementations=0.verified.txt | 84 -------- ...ingType=Int_implementations=2.verified.txt | 84 -------- ...ingType=Int_implementations=4.verified.txt | 85 -------- ...ingType=Int_implementations=6.verified.txt | 85 -------- ...ngType=Long_implementations=0.verified.txt | 84 -------- ...ngType=Long_implementations=2.verified.txt | 84 -------- ...ngType=Long_implementations=4.verified.txt | 85 -------- ...ngType=Long_implementations=6.verified.txt | 85 -------- ...ransitNewId_implementations=0.verified.txt | 85 -------- ...ransitNewId_implementations=2.verified.txt | 85 -------- ...ransitNewId_implementations=4.verified.txt | 86 -------- ...ransitNewId_implementations=6.verified.txt | 86 -------- ...lableString_implementations=0.verified.txt | 100 --------- ...lableString_implementations=2.verified.txt | 100 --------- ...lableString_implementations=4.verified.txt | 110 ---------- ...lableString_implementations=6.verified.txt | 110 ---------- ...Type=String_implementations=0.verified.txt | 93 --------- ...Type=String_implementations=2.verified.txt | 93 --------- ...Type=String_implementations=4.verified.txt | 103 ---------- ...Type=String_implementations=6.verified.txt | 103 ---------- ...ngType=Guid_implementations=0.verified.txt | 127 ------------ ...ngType=Guid_implementations=2.verified.txt | 127 ------------ ...ngType=Guid_implementations=4.verified.txt | 128 ------------ ...ngType=Guid_implementations=6.verified.txt | 128 ------------ ...ingType=Int_implementations=0.verified.txt | 126 ------------ ...ingType=Int_implementations=2.verified.txt | 126 ------------ ...ingType=Int_implementations=4.verified.txt | 127 ------------ ...ingType=Int_implementations=6.verified.txt | 127 ------------ ...ngType=Long_implementations=0.verified.txt | 128 ------------ ...ngType=Long_implementations=2.verified.txt | 128 ------------ ...ngType=Long_implementations=4.verified.txt | 129 ------------ ...ngType=Long_implementations=6.verified.txt | 129 ------------ ...ransitNewId_implementations=0.verified.txt | 135 ------------ ...ransitNewId_implementations=2.verified.txt | 135 ------------ ...ransitNewId_implementations=4.verified.txt | 136 ------------ ...ransitNewId_implementations=6.verified.txt | 136 ------------ ...lableString_implementations=0.verified.txt | 143 ------------- ...lableString_implementations=2.verified.txt | 143 ------------- ...lableString_implementations=4.verified.txt | 153 -------------- ...lableString_implementations=6.verified.txt | 153 -------------- ...Type=String_implementations=0.verified.txt | 131 ------------ ...Type=String_implementations=2.verified.txt | 131 ------------ ...Type=String_implementations=4.verified.txt | 141 ------------- ...Type=String_implementations=6.verified.txt | 141 ------------- ...ngType=Guid_implementations=0.verified.txt | 78 ------- ...ngType=Guid_implementations=2.verified.txt | 78 ------- ...ngType=Guid_implementations=4.verified.txt | 79 ------- ...ngType=Guid_implementations=6.verified.txt | 79 ------- ...ingType=Int_implementations=0.verified.txt | 77 ------- ...ingType=Int_implementations=2.verified.txt | 77 ------- ...ingType=Int_implementations=4.verified.txt | 78 ------- ...ingType=Int_implementations=6.verified.txt | 78 ------- ...ngType=Long_implementations=0.verified.txt | 77 ------- ...ngType=Long_implementations=2.verified.txt | 77 ------- ...ngType=Long_implementations=4.verified.txt | 78 ------- ...ngType=Long_implementations=6.verified.txt | 78 ------- ...ransitNewId_implementations=0.verified.txt | 78 ------- ...ransitNewId_implementations=2.verified.txt | 78 ------- ...ransitNewId_implementations=4.verified.txt | 79 ------- ...ransitNewId_implementations=6.verified.txt | 79 ------- ...lableString_implementations=0.verified.txt | 94 --------- ...lableString_implementations=2.verified.txt | 94 --------- ...lableString_implementations=4.verified.txt | 104 ---------- ...lableString_implementations=6.verified.txt | 104 ---------- ...Type=String_implementations=0.verified.txt | 87 -------- ...Type=String_implementations=2.verified.txt | 87 -------- ...Type=String_implementations=4.verified.txt | 97 --------- ...Type=String_implementations=6.verified.txt | 97 --------- ...ngType=Guid_implementations=0.verified.txt | 120 ----------- ...ngType=Guid_implementations=2.verified.txt | 120 ----------- ...ngType=Guid_implementations=4.verified.txt | 121 ----------- ...ngType=Guid_implementations=6.verified.txt | 121 ----------- ...ingType=Int_implementations=0.verified.txt | 119 ----------- ...ingType=Int_implementations=2.verified.txt | 119 ----------- ...ingType=Int_implementations=4.verified.txt | 120 ----------- ...ingType=Int_implementations=6.verified.txt | 120 ----------- ...ngType=Long_implementations=0.verified.txt | 121 ----------- ...ngType=Long_implementations=2.verified.txt | 121 ----------- ...ngType=Long_implementations=4.verified.txt | 122 ----------- ...ngType=Long_implementations=6.verified.txt | 122 ----------- ...ransitNewId_implementations=0.verified.txt | 128 ------------ ...ransitNewId_implementations=2.verified.txt | 128 ------------ ...ransitNewId_implementations=4.verified.txt | 129 ------------ ...ransitNewId_implementations=6.verified.txt | 129 ------------ ...lableString_implementations=0.verified.txt | 137 ------------- ...lableString_implementations=2.verified.txt | 137 ------------- ...lableString_implementations=4.verified.txt | 147 ------------- ...lableString_implementations=6.verified.txt | 147 ------------- ...Type=String_implementations=0.verified.txt | 125 ------------ ...Type=String_implementations=2.verified.txt | 125 ------------ ...Type=String_implementations=4.verified.txt | 135 ------------ ...Type=String_implementations=6.verified.txt | 135 ------------ ...ngType=Guid_implementations=0.verified.txt | 99 --------- ...ngType=Guid_implementations=2.verified.txt | 99 --------- ...ngType=Guid_implementations=4.verified.txt | 100 --------- ...ngType=Guid_implementations=6.verified.txt | 100 --------- ...ingType=Int_implementations=0.verified.txt | 98 --------- ...ingType=Int_implementations=2.verified.txt | 98 --------- ...ingType=Int_implementations=4.verified.txt | 99 --------- ...ingType=Int_implementations=6.verified.txt | 99 --------- ...ngType=Long_implementations=0.verified.txt | 98 --------- ...ngType=Long_implementations=2.verified.txt | 98 --------- ...ngType=Long_implementations=4.verified.txt | 99 --------- ...ngType=Long_implementations=6.verified.txt | 99 --------- ...ransitNewId_implementations=0.verified.txt | 99 --------- ...ransitNewId_implementations=2.verified.txt | 99 --------- ...ransitNewId_implementations=4.verified.txt | 100 --------- ...ransitNewId_implementations=6.verified.txt | 100 --------- ...lableString_implementations=0.verified.txt | 121 ----------- ...lableString_implementations=2.verified.txt | 121 ----------- ...lableString_implementations=4.verified.txt | 131 ------------ ...lableString_implementations=6.verified.txt | 131 ------------ ...Type=String_implementations=0.verified.txt | 107 ---------- ...Type=String_implementations=2.verified.txt | 107 ---------- ...Type=String_implementations=4.verified.txt | 117 ----------- ...Type=String_implementations=6.verified.txt | 117 ----------- ...ngType=Guid_implementations=0.verified.txt | 141 ------------- ...ngType=Guid_implementations=2.verified.txt | 141 ------------- ...ngType=Guid_implementations=4.verified.txt | 142 ------------- ...ngType=Guid_implementations=6.verified.txt | 142 ------------- ...ingType=Int_implementations=0.verified.txt | 140 ------------- ...ingType=Int_implementations=2.verified.txt | 140 ------------- ...ingType=Int_implementations=4.verified.txt | 141 ------------- ...ingType=Int_implementations=6.verified.txt | 141 ------------- ...ngType=Long_implementations=0.verified.txt | 142 ------------- ...ngType=Long_implementations=2.verified.txt | 142 ------------- ...ngType=Long_implementations=4.verified.txt | 143 ------------- ...ngType=Long_implementations=6.verified.txt | 143 ------------- ...ransitNewId_implementations=0.verified.txt | 149 -------------- ...ransitNewId_implementations=2.verified.txt | 149 -------------- ...ransitNewId_implementations=4.verified.txt | 150 -------------- ...ransitNewId_implementations=6.verified.txt | 150 -------------- ...lableString_implementations=0.verified.txt | 164 --------------- ...lableString_implementations=2.verified.txt | 164 --------------- ...lableString_implementations=4.verified.txt | 174 ---------------- ...lableString_implementations=6.verified.txt | 174 ---------------- ...Type=String_implementations=0.verified.txt | 145 ------------- ...Type=String_implementations=2.verified.txt | 145 ------------- ...Type=String_implementations=4.verified.txt | 155 -------------- ...Type=String_implementations=6.verified.txt | 155 -------------- ...ngType=Guid_implementations=0.verified.txt | 71 ------- ...ngType=Guid_implementations=2.verified.txt | 71 ------- ...ngType=Guid_implementations=4.verified.txt | 72 ------- ...ngType=Guid_implementations=6.verified.txt | 72 ------- ...ingType=Int_implementations=0.verified.txt | 71 ------- ...ingType=Int_implementations=2.verified.txt | 71 ------- ...ingType=Int_implementations=4.verified.txt | 72 ------- ...ingType=Int_implementations=6.verified.txt | 72 ------- ...ngType=Long_implementations=0.verified.txt | 72 ------- ...ngType=Long_implementations=2.verified.txt | 72 ------- ...ngType=Long_implementations=4.verified.txt | 73 ------- ...ngType=Long_implementations=6.verified.txt | 73 ------- ...ransitNewId_implementations=0.verified.txt | 71 ------- ...ransitNewId_implementations=2.verified.txt | 71 ------- ...ransitNewId_implementations=4.verified.txt | 72 ------- ...ransitNewId_implementations=6.verified.txt | 72 ------- ...lableString_implementations=0.verified.txt | 81 -------- ...lableString_implementations=2.verified.txt | 81 -------- ...lableString_implementations=4.verified.txt | 91 --------- ...lableString_implementations=6.verified.txt | 91 --------- ...Type=String_implementations=0.verified.txt | 79 ------- ...Type=String_implementations=2.verified.txt | 79 ------- ...Type=String_implementations=4.verified.txt | 89 -------- ...Type=String_implementations=6.verified.txt | 89 -------- ...ngType=Guid_implementations=0.verified.txt | 113 ---------- ...ngType=Guid_implementations=2.verified.txt | 113 ---------- ...ngType=Guid_implementations=4.verified.txt | 114 ----------- ...ngType=Guid_implementations=6.verified.txt | 114 ----------- ...ingType=Int_implementations=0.verified.txt | 113 ---------- ...ingType=Int_implementations=2.verified.txt | 113 ---------- ...ingType=Int_implementations=4.verified.txt | 114 ----------- ...ingType=Int_implementations=6.verified.txt | 114 ----------- ...ngType=Long_implementations=0.verified.txt | 116 ----------- ...ngType=Long_implementations=2.verified.txt | 116 ----------- ...ngType=Long_implementations=4.verified.txt | 117 ----------- ...ngType=Long_implementations=6.verified.txt | 117 ----------- ...ransitNewId_implementations=0.verified.txt | 121 ----------- ...ransitNewId_implementations=2.verified.txt | 121 ----------- ...ransitNewId_implementations=4.verified.txt | 122 ----------- ...ransitNewId_implementations=6.verified.txt | 122 ----------- ...lableString_implementations=0.verified.txt | 124 ----------- ...lableString_implementations=2.verified.txt | 124 ----------- ...lableString_implementations=4.verified.txt | 134 ------------ ...lableString_implementations=6.verified.txt | 134 ------------ ...Type=String_implementations=0.verified.txt | 117 ----------- ...Type=String_implementations=2.verified.txt | 117 ----------- ...Type=String_implementations=4.verified.txt | 127 ------------ ...Type=String_implementations=6.verified.txt | 127 ------------ ...ngType=Guid_implementations=0.verified.txt | 89 -------- ...ngType=Guid_implementations=2.verified.txt | 89 -------- ...ngType=Guid_implementations=4.verified.txt | 90 -------- ...ngType=Guid_implementations=6.verified.txt | 90 -------- ...ingType=Int_implementations=0.verified.txt | 89 -------- ...ingType=Int_implementations=2.verified.txt | 89 -------- ...ingType=Int_implementations=4.verified.txt | 90 -------- ...ingType=Int_implementations=6.verified.txt | 90 -------- ...ngType=Long_implementations=0.verified.txt | 90 -------- ...ngType=Long_implementations=2.verified.txt | 90 -------- ...ngType=Long_implementations=4.verified.txt | 91 --------- ...ngType=Long_implementations=6.verified.txt | 91 --------- ...ransitNewId_implementations=0.verified.txt | 89 -------- ...ransitNewId_implementations=2.verified.txt | 89 -------- ...ransitNewId_implementations=4.verified.txt | 90 -------- ...ransitNewId_implementations=6.verified.txt | 90 -------- ...lableString_implementations=0.verified.txt | 105 ---------- ...lableString_implementations=2.verified.txt | 105 ---------- ...lableString_implementations=4.verified.txt | 115 ----------- ...lableString_implementations=6.verified.txt | 115 ----------- ...Type=String_implementations=0.verified.txt | 96 --------- ...Type=String_implementations=2.verified.txt | 96 --------- ...Type=String_implementations=4.verified.txt | 106 ---------- ...Type=String_implementations=6.verified.txt | 106 ---------- ...ngType=Guid_implementations=0.verified.txt | 131 ------------ ...ngType=Guid_implementations=2.verified.txt | 131 ------------ ...ngType=Guid_implementations=4.verified.txt | 132 ------------ ...ngType=Guid_implementations=6.verified.txt | 132 ------------ ...ingType=Int_implementations=0.verified.txt | 131 ------------ ...ingType=Int_implementations=2.verified.txt | 131 ------------ ...ingType=Int_implementations=4.verified.txt | 132 ------------ ...ingType=Int_implementations=6.verified.txt | 132 ------------ ...ngType=Long_implementations=0.verified.txt | 134 ------------ ...ngType=Long_implementations=2.verified.txt | 134 ------------ ...ngType=Long_implementations=4.verified.txt | 135 ------------ ...ngType=Long_implementations=6.verified.txt | 135 ------------ ...ransitNewId_implementations=0.verified.txt | 139 ------------- ...ransitNewId_implementations=2.verified.txt | 139 ------------- ...ransitNewId_implementations=4.verified.txt | 140 ------------- ...ransitNewId_implementations=6.verified.txt | 140 ------------- ...lableString_implementations=0.verified.txt | 148 -------------- ...lableString_implementations=2.verified.txt | 148 -------------- ...lableString_implementations=4.verified.txt | 158 -------------- ...lableString_implementations=6.verified.txt | 158 -------------- ...Type=String_implementations=0.verified.txt | 134 ------------ ...Type=String_implementations=2.verified.txt | 134 ------------ ...Type=String_implementations=4.verified.txt | 144 ------------- ...Type=String_implementations=6.verified.txt | 144 ------------- ...ngType=Guid_implementations=0.verified.txt | 82 -------- ...ngType=Guid_implementations=2.verified.txt | 82 -------- ...ngType=Guid_implementations=4.verified.txt | 83 -------- ...ngType=Guid_implementations=6.verified.txt | 83 -------- ...ingType=Int_implementations=0.verified.txt | 82 -------- ...ingType=Int_implementations=2.verified.txt | 82 -------- ...ingType=Int_implementations=4.verified.txt | 83 -------- ...ingType=Int_implementations=6.verified.txt | 83 -------- ...ngType=Long_implementations=0.verified.txt | 83 -------- ...ngType=Long_implementations=2.verified.txt | 83 -------- ...ngType=Long_implementations=4.verified.txt | 84 -------- ...ngType=Long_implementations=6.verified.txt | 84 -------- ...ransitNewId_implementations=0.verified.txt | 82 -------- ...ransitNewId_implementations=2.verified.txt | 82 -------- ...ransitNewId_implementations=4.verified.txt | 83 -------- ...ransitNewId_implementations=6.verified.txt | 83 -------- ...lableString_implementations=0.verified.txt | 99 --------- ...lableString_implementations=2.verified.txt | 99 --------- ...lableString_implementations=4.verified.txt | 109 ---------- ...lableString_implementations=6.verified.txt | 109 ---------- ...Type=String_implementations=0.verified.txt | 90 -------- ...Type=String_implementations=2.verified.txt | 90 -------- ...Type=String_implementations=4.verified.txt | 100 --------- ...Type=String_implementations=6.verified.txt | 100 --------- ...ngType=Guid_implementations=0.verified.txt | 124 ----------- ...ngType=Guid_implementations=2.verified.txt | 124 ----------- ...ngType=Guid_implementations=4.verified.txt | 125 ------------ ...ngType=Guid_implementations=6.verified.txt | 125 ------------ ...ingType=Int_implementations=0.verified.txt | 124 ----------- ...ingType=Int_implementations=2.verified.txt | 124 ----------- ...ingType=Int_implementations=4.verified.txt | 125 ------------ ...ingType=Int_implementations=6.verified.txt | 125 ------------ ...ngType=Long_implementations=0.verified.txt | 127 ------------ ...ngType=Long_implementations=2.verified.txt | 127 ------------ ...ngType=Long_implementations=4.verified.txt | 128 ------------ ...ngType=Long_implementations=6.verified.txt | 128 ------------ ...ransitNewId_implementations=0.verified.txt | 132 ------------ ...ransitNewId_implementations=2.verified.txt | 132 ------------ ...ransitNewId_implementations=4.verified.txt | 133 ------------ ...ransitNewId_implementations=6.verified.txt | 133 ------------ ...lableString_implementations=0.verified.txt | 142 ------------- ...lableString_implementations=2.verified.txt | 142 ------------- ...lableString_implementations=4.verified.txt | 152 -------------- ...lableString_implementations=6.verified.txt | 152 -------------- ...Type=String_implementations=0.verified.txt | 128 ------------ ...Type=String_implementations=2.verified.txt | 128 ------------ ...Type=String_implementations=4.verified.txt | 138 ------------- ...Type=String_implementations=6.verified.txt | 138 ------------- ...ngType=Guid_implementations=0.verified.txt | 103 ---------- ...ngType=Guid_implementations=2.verified.txt | 103 ---------- ...ngType=Guid_implementations=4.verified.txt | 104 ---------- ...ngType=Guid_implementations=6.verified.txt | 104 ---------- ...ingType=Int_implementations=0.verified.txt | 103 ---------- ...ingType=Int_implementations=2.verified.txt | 103 ---------- ...ingType=Int_implementations=4.verified.txt | 104 ---------- ...ingType=Int_implementations=6.verified.txt | 104 ---------- ...ngType=Long_implementations=0.verified.txt | 104 ---------- ...ngType=Long_implementations=2.verified.txt | 104 ---------- ...ngType=Long_implementations=4.verified.txt | 105 ---------- ...ngType=Long_implementations=6.verified.txt | 105 ---------- ...ransitNewId_implementations=0.verified.txt | 103 ---------- ...ransitNewId_implementations=2.verified.txt | 103 ---------- ...ransitNewId_implementations=4.verified.txt | 104 ---------- ...ransitNewId_implementations=6.verified.txt | 104 ---------- ...lableString_implementations=0.verified.txt | 126 ------------ ...lableString_implementations=2.verified.txt | 126 ------------ ...lableString_implementations=4.verified.txt | 136 ------------ ...lableString_implementations=6.verified.txt | 136 ------------ ...Type=String_implementations=0.verified.txt | 110 ---------- ...Type=String_implementations=2.verified.txt | 110 ---------- ...Type=String_implementations=4.verified.txt | 120 ----------- ...Type=String_implementations=6.verified.txt | 120 ----------- ...ngType=Guid_implementations=0.verified.txt | 145 ------------- ...ngType=Guid_implementations=2.verified.txt | 145 ------------- ...ngType=Guid_implementations=4.verified.txt | 146 ------------- ...ngType=Guid_implementations=6.verified.txt | 146 ------------- ...ingType=Int_implementations=0.verified.txt | 145 ------------- ...ingType=Int_implementations=2.verified.txt | 145 ------------- ...ingType=Int_implementations=4.verified.txt | 146 ------------- ...ingType=Int_implementations=6.verified.txt | 146 ------------- ...ngType=Long_implementations=0.verified.txt | 148 -------------- ...ngType=Long_implementations=2.verified.txt | 148 -------------- ...ngType=Long_implementations=4.verified.txt | 149 -------------- ...ngType=Long_implementations=6.verified.txt | 149 -------------- ...ransitNewId_implementations=0.verified.txt | 153 -------------- ...ransitNewId_implementations=2.verified.txt | 153 -------------- ...ransitNewId_implementations=4.verified.txt | 154 -------------- ...ransitNewId_implementations=6.verified.txt | 154 -------------- ...lableString_implementations=0.verified.txt | 169 --------------- ...lableString_implementations=2.verified.txt | 169 --------------- ...lableString_implementations=4.verified.txt | 179 ---------------- ...lableString_implementations=6.verified.txt | 179 ---------------- ...Type=String_implementations=0.verified.txt | 148 -------------- ...Type=String_implementations=2.verified.txt | 148 -------------- ...Type=String_implementations=4.verified.txt | 158 -------------- ...Type=String_implementations=6.verified.txt | 158 -------------- ...ngType=Guid_implementations=0.verified.txt | 79 ------- ...ngType=Guid_implementations=2.verified.txt | 79 ------- ...ngType=Guid_implementations=4.verified.txt | 80 -------- ...ngType=Guid_implementations=6.verified.txt | 80 -------- ...ingType=Int_implementations=0.verified.txt | 79 ------- ...ingType=Int_implementations=2.verified.txt | 79 ------- ...ingType=Int_implementations=4.verified.txt | 80 -------- ...ingType=Int_implementations=6.verified.txt | 80 -------- ...ngType=Long_implementations=0.verified.txt | 80 -------- ...ngType=Long_implementations=2.verified.txt | 80 -------- ...ngType=Long_implementations=4.verified.txt | 81 -------- ...ngType=Long_implementations=6.verified.txt | 81 -------- ...ransitNewId_implementations=0.verified.txt | 79 ------- ...ransitNewId_implementations=2.verified.txt | 79 ------- ...ransitNewId_implementations=4.verified.txt | 80 -------- ...ransitNewId_implementations=6.verified.txt | 80 -------- ...lableString_implementations=0.verified.txt | 89 -------- ...lableString_implementations=2.verified.txt | 89 -------- ...lableString_implementations=4.verified.txt | 99 --------- ...lableString_implementations=6.verified.txt | 99 --------- ...Type=String_implementations=0.verified.txt | 87 -------- ...Type=String_implementations=2.verified.txt | 87 -------- ...Type=String_implementations=4.verified.txt | 97 --------- ...Type=String_implementations=6.verified.txt | 97 --------- ...ngType=Guid_implementations=0.verified.txt | 121 ----------- ...ngType=Guid_implementations=2.verified.txt | 121 ----------- ...ngType=Guid_implementations=4.verified.txt | 122 ----------- ...ngType=Guid_implementations=6.verified.txt | 122 ----------- ...ingType=Int_implementations=0.verified.txt | 121 ----------- ...ingType=Int_implementations=2.verified.txt | 121 ----------- ...ingType=Int_implementations=4.verified.txt | 122 ----------- ...ingType=Int_implementations=6.verified.txt | 122 ----------- ...ngType=Long_implementations=0.verified.txt | 124 ----------- ...ngType=Long_implementations=2.verified.txt | 124 ----------- ...ngType=Long_implementations=4.verified.txt | 125 ------------ ...ngType=Long_implementations=6.verified.txt | 125 ------------ ...ransitNewId_implementations=0.verified.txt | 129 ------------ ...ransitNewId_implementations=2.verified.txt | 129 ------------ ...ransitNewId_implementations=4.verified.txt | 130 ------------ ...ransitNewId_implementations=6.verified.txt | 130 ------------ ...lableString_implementations=0.verified.txt | 132 ------------ ...lableString_implementations=2.verified.txt | 132 ------------ ...lableString_implementations=4.verified.txt | 142 ------------- ...lableString_implementations=6.verified.txt | 142 ------------- ...Type=String_implementations=0.verified.txt | 125 ------------ ...Type=String_implementations=2.verified.txt | 125 ------------ ...Type=String_implementations=4.verified.txt | 135 ------------ ...Type=String_implementations=6.verified.txt | 135 ------------ ...ngType=Guid_implementations=0.verified.txt | 100 --------- ...ngType=Guid_implementations=2.verified.txt | 100 --------- ...ngType=Guid_implementations=4.verified.txt | 101 --------- ...ngType=Guid_implementations=6.verified.txt | 101 --------- ...ingType=Int_implementations=0.verified.txt | 100 --------- ...ingType=Int_implementations=2.verified.txt | 100 --------- ...ingType=Int_implementations=4.verified.txt | 101 --------- ...ingType=Int_implementations=6.verified.txt | 101 --------- ...ngType=Long_implementations=0.verified.txt | 101 --------- ...ngType=Long_implementations=2.verified.txt | 101 --------- ...ngType=Long_implementations=4.verified.txt | 102 --------- ...ngType=Long_implementations=6.verified.txt | 102 --------- ...ransitNewId_implementations=0.verified.txt | 100 --------- ...ransitNewId_implementations=2.verified.txt | 100 --------- ...ransitNewId_implementations=4.verified.txt | 101 --------- ...ransitNewId_implementations=6.verified.txt | 101 --------- ...lableString_implementations=0.verified.txt | 116 ----------- ...lableString_implementations=2.verified.txt | 116 ----------- ...lableString_implementations=4.verified.txt | 126 ------------ ...lableString_implementations=6.verified.txt | 126 ------------ ...Type=String_implementations=0.verified.txt | 107 ---------- ...Type=String_implementations=2.verified.txt | 107 ---------- ...Type=String_implementations=4.verified.txt | 117 ----------- ...Type=String_implementations=6.verified.txt | 117 ----------- ...ngType=Guid_implementations=0.verified.txt | 142 ------------- ...ngType=Guid_implementations=2.verified.txt | 142 ------------- ...ngType=Guid_implementations=4.verified.txt | 143 ------------- ...ngType=Guid_implementations=6.verified.txt | 143 ------------- ...ingType=Int_implementations=0.verified.txt | 142 ------------- ...ingType=Int_implementations=2.verified.txt | 142 ------------- ...ingType=Int_implementations=4.verified.txt | 143 ------------- ...ingType=Int_implementations=6.verified.txt | 143 ------------- ...ngType=Long_implementations=0.verified.txt | 145 ------------- ...ngType=Long_implementations=2.verified.txt | 145 ------------- ...ngType=Long_implementations=4.verified.txt | 146 ------------- ...ngType=Long_implementations=6.verified.txt | 146 ------------- ...ransitNewId_implementations=0.verified.txt | 150 -------------- ...ransitNewId_implementations=2.verified.txt | 150 -------------- ...ransitNewId_implementations=4.verified.txt | 151 -------------- ...ransitNewId_implementations=6.verified.txt | 151 -------------- ...lableString_implementations=0.verified.txt | 159 --------------- ...lableString_implementations=2.verified.txt | 159 --------------- ...lableString_implementations=4.verified.txt | 169 --------------- ...lableString_implementations=6.verified.txt | 169 --------------- ...Type=String_implementations=0.verified.txt | 145 ------------- ...Type=String_implementations=2.verified.txt | 145 ------------- ...Type=String_implementations=4.verified.txt | 155 -------------- ...Type=String_implementations=6.verified.txt | 155 -------------- ...ngType=Guid_implementations=0.verified.txt | 93 --------- ...ngType=Guid_implementations=2.verified.txt | 93 --------- ...ngType=Guid_implementations=4.verified.txt | 94 --------- ...ngType=Guid_implementations=6.verified.txt | 94 --------- ...ingType=Int_implementations=0.verified.txt | 93 --------- ...ingType=Int_implementations=2.verified.txt | 93 --------- ...ingType=Int_implementations=4.verified.txt | 94 --------- ...ingType=Int_implementations=6.verified.txt | 94 --------- ...ngType=Long_implementations=0.verified.txt | 94 --------- ...ngType=Long_implementations=2.verified.txt | 94 --------- ...ngType=Long_implementations=4.verified.txt | 95 --------- ...ngType=Long_implementations=6.verified.txt | 95 --------- ...ransitNewId_implementations=0.verified.txt | 93 --------- ...ransitNewId_implementations=2.verified.txt | 93 --------- ...ransitNewId_implementations=4.verified.txt | 94 --------- ...ransitNewId_implementations=6.verified.txt | 94 --------- ...lableString_implementations=0.verified.txt | 110 ---------- ...lableString_implementations=2.verified.txt | 110 ---------- ...lableString_implementations=4.verified.txt | 120 ----------- ...lableString_implementations=6.verified.txt | 120 ----------- ...Type=String_implementations=0.verified.txt | 101 --------- ...Type=String_implementations=2.verified.txt | 101 --------- ...Type=String_implementations=4.verified.txt | 111 ---------- ...Type=String_implementations=6.verified.txt | 111 ---------- ...ngType=Guid_implementations=0.verified.txt | 135 ------------ ...ngType=Guid_implementations=2.verified.txt | 135 ------------ ...ngType=Guid_implementations=4.verified.txt | 136 ------------ ...ngType=Guid_implementations=6.verified.txt | 136 ------------ ...ingType=Int_implementations=0.verified.txt | 135 ------------ ...ingType=Int_implementations=2.verified.txt | 135 ------------ ...ingType=Int_implementations=4.verified.txt | 136 ------------ ...ingType=Int_implementations=6.verified.txt | 136 ------------ ...ngType=Long_implementations=0.verified.txt | 138 ------------- ...ngType=Long_implementations=2.verified.txt | 138 ------------- ...ngType=Long_implementations=4.verified.txt | 139 ------------- ...ngType=Long_implementations=6.verified.txt | 139 ------------- ...ransitNewId_implementations=0.verified.txt | 143 ------------- ...ransitNewId_implementations=2.verified.txt | 143 ------------- ...ransitNewId_implementations=4.verified.txt | 144 ------------- ...ransitNewId_implementations=6.verified.txt | 144 ------------- ...lableString_implementations=0.verified.txt | 153 -------------- ...lableString_implementations=2.verified.txt | 153 -------------- ...lableString_implementations=4.verified.txt | 163 --------------- ...lableString_implementations=6.verified.txt | 163 --------------- ...Type=String_implementations=0.verified.txt | 139 ------------- ...Type=String_implementations=2.verified.txt | 139 ------------- ...Type=String_implementations=4.verified.txt | 149 -------------- ...Type=String_implementations=6.verified.txt | 149 -------------- ...ngType=Guid_implementations=0.verified.txt | 114 ----------- ...ngType=Guid_implementations=2.verified.txt | 114 ----------- ...ngType=Guid_implementations=4.verified.txt | 115 ----------- ...ngType=Guid_implementations=6.verified.txt | 115 ----------- ...ingType=Int_implementations=0.verified.txt | 114 ----------- ...ingType=Int_implementations=2.verified.txt | 114 ----------- ...ingType=Int_implementations=4.verified.txt | 115 ----------- ...ingType=Int_implementations=6.verified.txt | 115 ----------- ...ngType=Long_implementations=0.verified.txt | 115 ----------- ...ngType=Long_implementations=2.verified.txt | 115 ----------- ...ngType=Long_implementations=4.verified.txt | 116 ----------- ...ngType=Long_implementations=6.verified.txt | 116 ----------- ...ransitNewId_implementations=0.verified.txt | 114 ----------- ...ransitNewId_implementations=2.verified.txt | 114 ----------- ...ransitNewId_implementations=4.verified.txt | 115 ----------- ...ransitNewId_implementations=6.verified.txt | 115 ----------- ...lableString_implementations=0.verified.txt | 137 ------------- ...lableString_implementations=2.verified.txt | 137 ------------- ...lableString_implementations=4.verified.txt | 147 ------------- ...lableString_implementations=6.verified.txt | 147 ------------- ...Type=String_implementations=0.verified.txt | 121 ----------- ...Type=String_implementations=2.verified.txt | 121 ----------- ...Type=String_implementations=4.verified.txt | 131 ------------ ...Type=String_implementations=6.verified.txt | 131 ------------ ...ngType=Guid_implementations=0.verified.txt | 156 -------------- ...ngType=Guid_implementations=2.verified.txt | 156 -------------- ...ngType=Guid_implementations=4.verified.txt | 157 -------------- ...ngType=Guid_implementations=6.verified.txt | 157 -------------- ...ingType=Int_implementations=0.verified.txt | 156 -------------- ...ingType=Int_implementations=2.verified.txt | 156 -------------- ...ingType=Int_implementations=4.verified.txt | 157 -------------- ...ingType=Int_implementations=6.verified.txt | 157 -------------- ...ngType=Long_implementations=0.verified.txt | 159 --------------- ...ngType=Long_implementations=2.verified.txt | 159 --------------- ...ngType=Long_implementations=4.verified.txt | 160 --------------- ...ngType=Long_implementations=6.verified.txt | 160 --------------- ...ransitNewId_implementations=0.verified.txt | 164 --------------- ...ransitNewId_implementations=2.verified.txt | 164 --------------- ...ransitNewId_implementations=4.verified.txt | 165 --------------- ...ransitNewId_implementations=6.verified.txt | 165 --------------- ...lableString_implementations=0.verified.txt | 180 ---------------- ...lableString_implementations=2.verified.txt | 180 ---------------- ...lableString_implementations=4.verified.txt | 190 ----------------- ...lableString_implementations=6.verified.txt | 190 ----------------- ...Type=String_implementations=0.verified.txt | 159 --------------- ...Type=String_implementations=2.verified.txt | 159 --------------- ...Type=String_implementations=4.verified.txt | 169 --------------- ...Type=String_implementations=6.verified.txt | 169 --------------- ...ngType=Guid_implementations=6.verified.txt | 51 ----- ...ingType=Int_implementations=6.verified.txt | 50 ----- ...ngType=Long_implementations=6.verified.txt | 50 ----- ...ransitNewId_implementations=6.verified.txt | 51 ----- ...lableString_implementations=6.verified.txt | 69 ------- ...Type=String_implementations=6.verified.txt | 69 ------- ...ngType=Guid_implementations=0.verified.txt | 92 --------- ...ngType=Guid_implementations=6.verified.txt | 93 --------- ...ingType=Int_implementations=0.verified.txt | 91 --------- ...ingType=Int_implementations=6.verified.txt | 92 --------- ...ngType=Long_implementations=0.verified.txt | 93 --------- ...ngType=Long_implementations=6.verified.txt | 94 --------- ...ransitNewId_implementations=0.verified.txt | 100 --------- ...ransitNewId_implementations=6.verified.txt | 101 --------- ...lableString_implementations=0.verified.txt | 102 --------- ...lableString_implementations=6.verified.txt | 112 ---------- ...Type=String_implementations=0.verified.txt | 97 --------- ...Type=String_implementations=6.verified.txt | 107 ---------- ...ngType=Guid_implementations=0.verified.txt | 71 ------- ...ngType=Guid_implementations=6.verified.txt | 72 ------- ...ingType=Int_implementations=0.verified.txt | 70 ------- ...ingType=Int_implementations=6.verified.txt | 71 ------- ...ngType=Long_implementations=0.verified.txt | 70 ------- ...ngType=Long_implementations=6.verified.txt | 71 ------- ...ransitNewId_implementations=0.verified.txt | 71 ------- ...ransitNewId_implementations=6.verified.txt | 72 ------- ...lableString_implementations=0.verified.txt | 86 -------- ...lableString_implementations=6.verified.txt | 96 --------- ...Type=String_implementations=0.verified.txt | 79 ------- ...Type=String_implementations=6.verified.txt | 89 -------- ...ngType=Guid_implementations=0.verified.txt | 113 ---------- ...ngType=Guid_implementations=2.verified.txt | 113 ---------- ...ngType=Guid_implementations=4.verified.txt | 114 ----------- ...ngType=Guid_implementations=6.verified.txt | 114 ----------- ...ingType=Int_implementations=0.verified.txt | 112 ---------- ...ingType=Int_implementations=2.verified.txt | 112 ---------- ...ingType=Int_implementations=4.verified.txt | 113 ---------- ...ingType=Int_implementations=6.verified.txt | 113 ---------- ...ngType=Long_implementations=0.verified.txt | 114 ----------- ...ngType=Long_implementations=2.verified.txt | 114 ----------- ...ngType=Long_implementations=4.verified.txt | 115 ----------- ...ngType=Long_implementations=6.verified.txt | 115 ----------- ...ransitNewId_implementations=0.verified.txt | 121 ----------- ...ransitNewId_implementations=2.verified.txt | 121 ----------- ...ransitNewId_implementations=4.verified.txt | 122 ----------- ...ransitNewId_implementations=6.verified.txt | 122 ----------- ...lableString_implementations=0.verified.txt | 129 ------------ ...lableString_implementations=2.verified.txt | 129 ------------ ...lableString_implementations=4.verified.txt | 139 ------------- ...lableString_implementations=6.verified.txt | 139 ------------- ...Type=String_implementations=0.verified.txt | 117 ----------- ...Type=String_implementations=2.verified.txt | 117 ----------- ...Type=String_implementations=4.verified.txt | 127 ------------ ...Type=String_implementations=6.verified.txt | 127 ------------ ...ngType=Guid_implementations=0.verified.txt | 64 ------ ...ngType=Guid_implementations=6.verified.txt | 65 ------ ...ingType=Int_implementations=0.verified.txt | 63 ------ ...ingType=Int_implementations=6.verified.txt | 64 ------ ...ngType=Long_implementations=0.verified.txt | 63 ------ ...ngType=Long_implementations=6.verified.txt | 64 ------ ...ransitNewId_implementations=0.verified.txt | 64 ------ ...ransitNewId_implementations=6.verified.txt | 65 ------ ...lableString_implementations=0.verified.txt | 80 -------- ...lableString_implementations=6.verified.txt | 90 -------- ...Type=String_implementations=0.verified.txt | 73 ------- ...Type=String_implementations=6.verified.txt | 83 -------- ...ngType=Guid_implementations=0.verified.txt | 106 ---------- ...ngType=Guid_implementations=2.verified.txt | 106 ---------- ...ngType=Guid_implementations=4.verified.txt | 107 ---------- ...ngType=Guid_implementations=6.verified.txt | 107 ---------- ...ingType=Int_implementations=0.verified.txt | 105 ---------- ...ingType=Int_implementations=2.verified.txt | 105 ---------- ...ingType=Int_implementations=4.verified.txt | 106 ---------- ...ingType=Int_implementations=6.verified.txt | 106 ---------- ...ngType=Long_implementations=0.verified.txt | 107 ---------- ...ngType=Long_implementations=2.verified.txt | 107 ---------- ...ngType=Long_implementations=4.verified.txt | 108 ---------- ...ngType=Long_implementations=6.verified.txt | 108 ---------- ...ransitNewId_implementations=0.verified.txt | 114 ----------- ...ransitNewId_implementations=2.verified.txt | 114 ----------- ...ransitNewId_implementations=4.verified.txt | 115 ----------- ...ransitNewId_implementations=6.verified.txt | 115 ----------- ...lableString_implementations=0.verified.txt | 123 ----------- ...lableString_implementations=2.verified.txt | 123 ----------- ...lableString_implementations=4.verified.txt | 133 ------------ ...lableString_implementations=6.verified.txt | 133 ------------ ...Type=String_implementations=0.verified.txt | 111 ---------- ...Type=String_implementations=2.verified.txt | 111 ---------- ...Type=String_implementations=4.verified.txt | 121 ----------- ...Type=String_implementations=6.verified.txt | 121 ----------- ...ngType=Guid_implementations=0.verified.txt | 85 -------- ...ngType=Guid_implementations=2.verified.txt | 85 -------- ...ngType=Guid_implementations=4.verified.txt | 86 -------- ...ngType=Guid_implementations=6.verified.txt | 86 -------- ...ingType=Int_implementations=0.verified.txt | 84 -------- ...ingType=Int_implementations=2.verified.txt | 84 -------- ...ingType=Int_implementations=4.verified.txt | 85 -------- ...ingType=Int_implementations=6.verified.txt | 85 -------- ...ngType=Long_implementations=0.verified.txt | 84 -------- ...ngType=Long_implementations=2.verified.txt | 84 -------- ...ngType=Long_implementations=4.verified.txt | 85 -------- ...ngType=Long_implementations=6.verified.txt | 85 -------- ...ransitNewId_implementations=0.verified.txt | 85 -------- ...ransitNewId_implementations=2.verified.txt | 85 -------- ...ransitNewId_implementations=4.verified.txt | 86 -------- ...ransitNewId_implementations=6.verified.txt | 86 -------- ...lableString_implementations=0.verified.txt | 107 ---------- ...lableString_implementations=2.verified.txt | 107 ---------- ...lableString_implementations=4.verified.txt | 117 ----------- ...lableString_implementations=6.verified.txt | 117 ----------- ...Type=String_implementations=0.verified.txt | 93 --------- ...Type=String_implementations=2.verified.txt | 93 --------- ...Type=String_implementations=4.verified.txt | 103 ---------- ...Type=String_implementations=6.verified.txt | 103 ---------- ...ngType=Guid_implementations=0.verified.txt | 127 ------------ ...ngType=Guid_implementations=2.verified.txt | 127 ------------ ...ngType=Guid_implementations=4.verified.txt | 128 ------------ ...ngType=Guid_implementations=6.verified.txt | 128 ------------ ...ingType=Int_implementations=0.verified.txt | 126 ------------ ...ingType=Int_implementations=2.verified.txt | 126 ------------ ...ingType=Int_implementations=4.verified.txt | 127 ------------ ...ingType=Int_implementations=6.verified.txt | 127 ------------ ...ngType=Long_implementations=0.verified.txt | 128 ------------ ...ngType=Long_implementations=2.verified.txt | 128 ------------ ...ngType=Long_implementations=4.verified.txt | 129 ------------ ...ngType=Long_implementations=6.verified.txt | 129 ------------ ...ransitNewId_implementations=0.verified.txt | 135 ------------ ...ransitNewId_implementations=2.verified.txt | 135 ------------ ...ransitNewId_implementations=4.verified.txt | 136 ------------ ...ransitNewId_implementations=6.verified.txt | 136 ------------ ...lableString_implementations=0.verified.txt | 150 -------------- ...lableString_implementations=2.verified.txt | 150 -------------- ...lableString_implementations=4.verified.txt | 160 --------------- ...lableString_implementations=6.verified.txt | 160 --------------- ...Type=String_implementations=0.verified.txt | 131 ------------ ...Type=String_implementations=2.verified.txt | 131 ------------ ...Type=String_implementations=4.verified.txt | 141 ------------- ...Type=String_implementations=6.verified.txt | 141 ------------- ...ngType=Guid_implementations=0.verified.txt | 61 ------ ...ngType=Guid_implementations=6.verified.txt | 62 ------ ...ingType=Int_implementations=0.verified.txt | 60 ------ ...ingType=Int_implementations=6.verified.txt | 61 ------ ...ngType=Long_implementations=0.verified.txt | 60 ------ ...ngType=Long_implementations=6.verified.txt | 61 ------ ...ransitNewId_implementations=0.verified.txt | 61 ------ ...ransitNewId_implementations=6.verified.txt | 62 ------ ...lableString_implementations=0.verified.txt | 70 ------- ...lableString_implementations=6.verified.txt | 80 -------- ...Type=String_implementations=0.verified.txt | 70 ------- ...Type=String_implementations=6.verified.txt | 80 -------- ...ngType=Guid_implementations=0.verified.txt | 103 ---------- ...ngType=Guid_implementations=2.verified.txt | 103 ---------- ...ngType=Guid_implementations=4.verified.txt | 104 ---------- ...ngType=Guid_implementations=6.verified.txt | 104 ---------- ...ingType=Int_implementations=0.verified.txt | 102 --------- ...ingType=Int_implementations=2.verified.txt | 102 --------- ...ingType=Int_implementations=4.verified.txt | 103 ---------- ...ingType=Int_implementations=6.verified.txt | 103 ---------- ...ngType=Long_implementations=0.verified.txt | 104 ---------- ...ngType=Long_implementations=2.verified.txt | 104 ---------- ...ngType=Long_implementations=4.verified.txt | 105 ---------- ...ngType=Long_implementations=6.verified.txt | 105 ---------- ...ransitNewId_implementations=0.verified.txt | 111 ---------- ...ransitNewId_implementations=2.verified.txt | 111 ---------- ...ransitNewId_implementations=4.verified.txt | 112 ---------- ...ransitNewId_implementations=6.verified.txt | 112 ---------- ...lableString_implementations=0.verified.txt | 113 ---------- ...lableString_implementations=2.verified.txt | 113 ---------- ...lableString_implementations=4.verified.txt | 123 ----------- ...lableString_implementations=6.verified.txt | 123 ----------- ...Type=String_implementations=0.verified.txt | 108 ---------- ...Type=String_implementations=2.verified.txt | 108 ---------- ...Type=String_implementations=4.verified.txt | 118 ----------- ...Type=String_implementations=6.verified.txt | 118 ----------- ...ngType=Guid_implementations=0.verified.txt | 82 -------- ...ngType=Guid_implementations=2.verified.txt | 82 -------- ...ngType=Guid_implementations=4.verified.txt | 83 -------- ...ngType=Guid_implementations=6.verified.txt | 83 -------- ...ingType=Int_implementations=0.verified.txt | 81 -------- ...ingType=Int_implementations=2.verified.txt | 81 -------- ...ingType=Int_implementations=4.verified.txt | 82 -------- ...ingType=Int_implementations=6.verified.txt | 82 -------- ...ngType=Long_implementations=0.verified.txt | 81 -------- ...ngType=Long_implementations=2.verified.txt | 81 -------- ...ngType=Long_implementations=4.verified.txt | 82 -------- ...ngType=Long_implementations=6.verified.txt | 82 -------- ...ransitNewId_implementations=0.verified.txt | 82 -------- ...ransitNewId_implementations=2.verified.txt | 82 -------- ...ransitNewId_implementations=4.verified.txt | 83 -------- ...ransitNewId_implementations=6.verified.txt | 83 -------- ...lableString_implementations=0.verified.txt | 97 --------- ...lableString_implementations=2.verified.txt | 97 --------- ...lableString_implementations=4.verified.txt | 107 ---------- ...lableString_implementations=6.verified.txt | 107 ---------- ...Type=String_implementations=0.verified.txt | 90 -------- ...Type=String_implementations=2.verified.txt | 90 -------- ...Type=String_implementations=4.verified.txt | 100 --------- ...Type=String_implementations=6.verified.txt | 100 --------- ...ngType=Guid_implementations=0.verified.txt | 124 ----------- ...ngType=Guid_implementations=2.verified.txt | 124 ----------- ...ngType=Guid_implementations=4.verified.txt | 125 ------------ ...ngType=Guid_implementations=6.verified.txt | 125 ------------ ...ingType=Int_implementations=0.verified.txt | 123 ----------- ...ingType=Int_implementations=2.verified.txt | 123 ----------- ...ingType=Int_implementations=4.verified.txt | 124 ----------- ...ingType=Int_implementations=6.verified.txt | 124 ----------- ...ngType=Long_implementations=0.verified.txt | 125 ------------ ...ngType=Long_implementations=2.verified.txt | 125 ------------ ...ngType=Long_implementations=4.verified.txt | 126 ------------ ...ngType=Long_implementations=6.verified.txt | 126 ------------ ...ransitNewId_implementations=0.verified.txt | 132 ------------ ...ransitNewId_implementations=2.verified.txt | 132 ------------ ...ransitNewId_implementations=4.verified.txt | 133 ------------ ...ransitNewId_implementations=6.verified.txt | 133 ------------ ...lableString_implementations=0.verified.txt | 140 ------------- ...lableString_implementations=2.verified.txt | 140 ------------- ...lableString_implementations=4.verified.txt | 150 -------------- ...lableString_implementations=6.verified.txt | 150 -------------- ...Type=String_implementations=0.verified.txt | 128 ------------ ...Type=String_implementations=2.verified.txt | 128 ------------ ...Type=String_implementations=4.verified.txt | 138 ------------- ...Type=String_implementations=6.verified.txt | 138 ------------- ...ngType=Guid_implementations=0.verified.txt | 75 ------- ...ngType=Guid_implementations=2.verified.txt | 75 ------- ...ngType=Guid_implementations=4.verified.txt | 76 ------- ...ngType=Guid_implementations=6.verified.txt | 76 ------- ...ingType=Int_implementations=0.verified.txt | 74 ------- ...ingType=Int_implementations=2.verified.txt | 74 ------- ...ingType=Int_implementations=4.verified.txt | 75 ------- ...ingType=Int_implementations=6.verified.txt | 75 ------- ...ngType=Long_implementations=0.verified.txt | 74 ------- ...ngType=Long_implementations=2.verified.txt | 74 ------- ...ngType=Long_implementations=4.verified.txt | 75 ------- ...ngType=Long_implementations=6.verified.txt | 75 ------- ...ransitNewId_implementations=0.verified.txt | 75 ------- ...ransitNewId_implementations=2.verified.txt | 75 ------- ...ransitNewId_implementations=4.verified.txt | 76 ------- ...ransitNewId_implementations=6.verified.txt | 76 ------- ...lableString_implementations=0.verified.txt | 91 --------- ...lableString_implementations=2.verified.txt | 91 --------- ...lableString_implementations=4.verified.txt | 101 --------- ...lableString_implementations=6.verified.txt | 101 --------- ...Type=String_implementations=0.verified.txt | 84 -------- ...Type=String_implementations=2.verified.txt | 84 -------- ...Type=String_implementations=4.verified.txt | 94 --------- ...Type=String_implementations=6.verified.txt | 94 --------- ...ngType=Guid_implementations=0.verified.txt | 117 ----------- ...ngType=Guid_implementations=2.verified.txt | 117 ----------- ...ngType=Guid_implementations=4.verified.txt | 118 ----------- ...ngType=Guid_implementations=6.verified.txt | 118 ----------- ...ingType=Int_implementations=0.verified.txt | 116 ----------- ...ingType=Int_implementations=2.verified.txt | 116 ----------- ...ingType=Int_implementations=4.verified.txt | 117 ----------- ...ingType=Int_implementations=6.verified.txt | 117 ----------- ...ngType=Long_implementations=0.verified.txt | 118 ----------- ...ngType=Long_implementations=2.verified.txt | 118 ----------- ...ngType=Long_implementations=4.verified.txt | 119 ----------- ...ngType=Long_implementations=6.verified.txt | 119 ----------- ...ransitNewId_implementations=0.verified.txt | 125 ------------ ...ransitNewId_implementations=2.verified.txt | 125 ------------ ...ransitNewId_implementations=4.verified.txt | 126 ------------ ...ransitNewId_implementations=6.verified.txt | 126 ------------ ...lableString_implementations=0.verified.txt | 134 ------------ ...lableString_implementations=2.verified.txt | 134 ------------ ...lableString_implementations=4.verified.txt | 144 ------------- ...lableString_implementations=6.verified.txt | 144 ------------- ...Type=String_implementations=0.verified.txt | 122 ----------- ...Type=String_implementations=2.verified.txt | 122 ----------- ...Type=String_implementations=4.verified.txt | 132 ------------ ...Type=String_implementations=6.verified.txt | 132 ------------ ...ngType=Guid_implementations=0.verified.txt | 96 --------- ...ngType=Guid_implementations=2.verified.txt | 96 --------- ...ngType=Guid_implementations=4.verified.txt | 97 --------- ...ngType=Guid_implementations=6.verified.txt | 97 --------- ...ingType=Int_implementations=0.verified.txt | 95 --------- ...ingType=Int_implementations=2.verified.txt | 95 --------- ...ingType=Int_implementations=4.verified.txt | 96 --------- ...ingType=Int_implementations=6.verified.txt | 96 --------- ...ngType=Long_implementations=0.verified.txt | 95 --------- ...ngType=Long_implementations=2.verified.txt | 95 --------- ...ngType=Long_implementations=4.verified.txt | 96 --------- ...ngType=Long_implementations=6.verified.txt | 96 --------- ...ransitNewId_implementations=0.verified.txt | 96 --------- ...ransitNewId_implementations=2.verified.txt | 96 --------- ...ransitNewId_implementations=4.verified.txt | 97 --------- ...ransitNewId_implementations=6.verified.txt | 97 --------- ...lableString_implementations=0.verified.txt | 118 ----------- ...lableString_implementations=2.verified.txt | 118 ----------- ...lableString_implementations=4.verified.txt | 128 ------------ ...lableString_implementations=6.verified.txt | 128 ------------ ...Type=String_implementations=0.verified.txt | 104 ---------- ...Type=String_implementations=2.verified.txt | 104 ---------- ...Type=String_implementations=4.verified.txt | 114 ----------- ...Type=String_implementations=6.verified.txt | 114 ----------- ...ngType=Guid_implementations=0.verified.txt | 138 ------------- ...ngType=Guid_implementations=2.verified.txt | 138 ------------- ...ngType=Guid_implementations=4.verified.txt | 139 ------------- ...ngType=Guid_implementations=6.verified.txt | 139 ------------- ...ingType=Int_implementations=0.verified.txt | 137 ------------- ...ingType=Int_implementations=2.verified.txt | 137 ------------- ...ingType=Int_implementations=4.verified.txt | 138 ------------- ...ingType=Int_implementations=6.verified.txt | 138 ------------- ...ngType=Long_implementations=0.verified.txt | 139 ------------- ...ngType=Long_implementations=2.verified.txt | 139 ------------- ...ngType=Long_implementations=4.verified.txt | 140 ------------- ...ngType=Long_implementations=6.verified.txt | 140 ------------- ...ransitNewId_implementations=0.verified.txt | 146 ------------- ...ransitNewId_implementations=2.verified.txt | 146 ------------- ...ransitNewId_implementations=4.verified.txt | 147 ------------- ...ransitNewId_implementations=6.verified.txt | 147 ------------- ...lableString_implementations=0.verified.txt | 161 --------------- ...lableString_implementations=2.verified.txt | 161 --------------- ...lableString_implementations=4.verified.txt | 171 ---------------- ...lableString_implementations=6.verified.txt | 171 ---------------- ...Type=String_implementations=0.verified.txt | 142 ------------- ...Type=String_implementations=2.verified.txt | 142 ------------- ...Type=String_implementations=4.verified.txt | 152 -------------- ...Type=String_implementations=6.verified.txt | 152 -------------- ...ngType=Guid_implementations=0.verified.txt | 68 ------ ...ngType=Guid_implementations=6.verified.txt | 69 ------- ...ingType=Int_implementations=0.verified.txt | 68 ------ ...ingType=Int_implementations=6.verified.txt | 69 ------- ...ngType=Long_implementations=0.verified.txt | 69 ------- ...ngType=Long_implementations=6.verified.txt | 70 ------- ...ransitNewId_implementations=0.verified.txt | 68 ------ ...ransitNewId_implementations=6.verified.txt | 69 ------- ...lableString_implementations=0.verified.txt | 78 ------- ...lableString_implementations=6.verified.txt | 88 -------- ...Type=String_implementations=0.verified.txt | 76 ------- ...Type=String_implementations=6.verified.txt | 86 -------- ...ngType=Guid_implementations=0.verified.txt | 110 ---------- ...ngType=Guid_implementations=2.verified.txt | 110 ---------- ...ngType=Guid_implementations=4.verified.txt | 111 ---------- ...ngType=Guid_implementations=6.verified.txt | 111 ---------- ...ingType=Int_implementations=0.verified.txt | 110 ---------- ...ingType=Int_implementations=2.verified.txt | 110 ---------- ...ingType=Int_implementations=4.verified.txt | 111 ---------- ...ingType=Int_implementations=6.verified.txt | 111 ---------- ...ngType=Long_implementations=0.verified.txt | 113 ---------- ...ngType=Long_implementations=2.verified.txt | 113 ---------- ...ngType=Long_implementations=4.verified.txt | 114 ----------- ...ngType=Long_implementations=6.verified.txt | 114 ----------- ...ransitNewId_implementations=0.verified.txt | 118 ----------- ...ransitNewId_implementations=2.verified.txt | 118 ----------- ...ransitNewId_implementations=4.verified.txt | 119 ----------- ...ransitNewId_implementations=6.verified.txt | 119 ----------- ...lableString_implementations=0.verified.txt | 121 ----------- ...lableString_implementations=2.verified.txt | 121 ----------- ...lableString_implementations=4.verified.txt | 131 ------------ ...lableString_implementations=6.verified.txt | 131 ------------ ...Type=String_implementations=0.verified.txt | 114 ----------- ...Type=String_implementations=2.verified.txt | 114 ----------- ...Type=String_implementations=4.verified.txt | 124 ----------- ...Type=String_implementations=6.verified.txt | 124 ----------- ...perTypeHandler_i=IComparable.verified.txt} | 14 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 14 -- ...ValueConverter_i=IComparable.verified.txt} | 14 -- ...eValueConverter_i=IEquatable.verified.txt} | 14 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 14 -- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 14 -- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 14 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 14 -- ...=TypeConverter_i=IComparable.verified.txt} | 14 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 14 -- ...perTypeHandler_i=IComparable.verified.txt} | 14 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 14 -- ...ValueConverter_i=IComparable.verified.txt} | 14 -- ...eValueConverter_i=IEquatable.verified.txt} | 14 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 14 -- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 14 -- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 14 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 14 -- ...=TypeConverter_i=IComparable.verified.txt} | 14 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 14 -- ...perTypeHandler_i=IComparable.verified.txt} | 14 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 14 -- ...ValueConverter_i=IComparable.verified.txt} | 14 -- ...eValueConverter_i=IEquatable.verified.txt} | 14 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 14 -- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 14 -- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 14 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 14 -- ...=TypeConverter_i=IComparable.verified.txt} | 14 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 14 -- ...perTypeHandler_i=IComparable.verified.txt} | 14 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 14 -- ...ValueConverter_i=IComparable.verified.txt} | 14 -- ...eValueConverter_i=IEquatable.verified.txt} | 14 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 14 -- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 14 -- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 14 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 14 -- ...=TypeConverter_i=IComparable.verified.txt} | 14 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 14 -- ...perTypeHandler_i=IComparable.verified.txt} | 15 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 15 -- ...ValueConverter_i=IComparable.verified.txt} | 15 -- ...eValueConverter_i=IEquatable.verified.txt} | 15 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 15 -- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 15 -- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 15 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 15 -- ...=TypeConverter_i=IComparable.verified.txt} | 15 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 15 -- ...perTypeHandler_i=IComparable.verified.txt} | 15 -- ...pperTypeHandler_i=IEquatable.verified.txt} | 15 -- ...ValueConverter_i=IComparable.verified.txt} | 15 -- ...eValueConverter_i=IEquatable.verified.txt} | 15 -- ...NewtonsoftJson_i=IComparable.verified.txt} | 22 +- ...=NewtonsoftJson_i=IEquatable.verified.txt} | 22 +- ...erSchemaFilter_i=IComparable.verified.txt} | 0 ...gerSchemaFilter_i=IEquatable.verified.txt} | 0 ...c=SwaggerSchemaFilter_i=None.verified.txt} | 0 ...SystemTextJson_i=IComparable.verified.txt} | 15 -- ...=SystemTextJson_i=IEquatable.verified.txt} | 15 -- ...=TypeConverter_i=IComparable.verified.txt} | 15 -- ...c=TypeConverter_i=IEquatable.verified.txt} | 15 -- ...ateDefaultIdInGlobalNamespace.verified.txt | 6 + ...nerateIdInFileScopedNamespace.verified.txt | 6 + ...ests.CanGenerateIdInNamespace.verified.txt | 6 + ...ewtonsoftJson, SystemTextJson.verified.txt | 6 + ...Guid_converter=NewtonsoftJson.verified.txt | 6 + ...Guid_converter=SystemTextJson.verified.txt | 6 + ...=Guid_converter=TypeConverter.verified.txt | 6 + ...ckingType=Guid_converter=null.verified.txt | 6 + ...ewtonsoftJson, SystemTextJson.verified.txt | 6 + ...Guid_converter=NewtonsoftJson.verified.txt | 6 + ...Guid_converter=SystemTextJson.verified.txt | 6 + ...=Guid_converter=TypeConverter.verified.txt | 6 + ...ckingType=Guid_converter=null.verified.txt | 6 + ...nerateMultipleIdsWithSameName.verified.txt | 6 + ...eNestedIdInFileScopeNamespace.verified.txt | 6 + ...yNestedIdInFileScopeNamespace.verified.txt | 6 + ...eDefaultsUsingGlobalAttribute.verified.txt | 6 + .../SourceGenerationHelperSnapshotTests.cs | 13 +- .../StronglyTypedIds.Tests.csproj | 3 +- 1565 files changed, 236 insertions(+), 165815 deletions(-) delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt} (72%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt} (71%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt} (71%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt} (81%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt} (81%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt} (72%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt} (71%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt} (77%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt} (84%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt} (84%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt} (77%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt} (72%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt} (79%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt} (77%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt} (78%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt} (81%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt} (75%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt} (73%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt} (78%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt} (76%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt} (74%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt} (82%) rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt} (80%) diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index cd44309c6..e61f35fd7 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28803.352 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EE1258BD-3422-4F55-B9CF-B4D6C95DAD68}" EndProject @@ -18,19 +18,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution version.props = version.props EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Tests", "test\StronglyTypedIds.Tests\StronglyTypedIds.Tests.csproj", "{00B5ED3F-827D-41CD-9AF2-A9A20A6604E1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Tests", "test\StronglyTypedIds.Tests\StronglyTypedIds.Tests.csproj", "{00B5ED3F-827D-41CD-9AF2-A9A20A6604E1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.IntegrationTests", "test\StronglyTypedIds.IntegrationTests\StronglyTypedIds.IntegrationTests.csproj", "{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.IntegrationTests", "test\StronglyTypedIds.IntegrationTests\StronglyTypedIds.IntegrationTests.csproj", "{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{E13FB452-2D47-4719-8BAA-7B695D79AF3A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Attributes", "src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj", "{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Attributes", "src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj", "{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.IntegrationTests", "test\StronglyTypedIds.Nuget.IntegrationTests\StronglyTypedIds.Nuget.IntegrationTests.csproj", "{A7355210-7DDC-4968-84B7-79002113EA6E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Nuget.IntegrationTests", "test\StronglyTypedIds.Nuget.IntegrationTests\StronglyTypedIds.Nuget.IntegrationTests.csproj", "{A7355210-7DDC-4968-84B7-79002113EA6E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.Attributes.IntegrationTests", "test\StronglyTypedIds.Nuget.Attributes.IntegrationTests\StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj", "{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Nuget.Attributes.IntegrationTests", "test\StronglyTypedIds.Nuget.Attributes.IntegrationTests\StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj", "{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -42,8 +42,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU {9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -80,6 +78,16 @@ Global {09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x64.Build.0 = Release|Any CPU {09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x86.ActiveCfg = Release|Any CPU {09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x86.Build.0 = Release|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x64.ActiveCfg = Debug|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x64.Build.0 = Debug|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x86.ActiveCfg = Debug|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x86.Build.0 = Debug|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x64.ActiveCfg = Release|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x64.Build.0 = Release|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x86.ActiveCfg = Release|Any CPU + {E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x86.Build.0 = Release|Any CPU {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|Any CPU.Build.0 = Debug|Any CPU {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -93,12 +101,14 @@ Global {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Release|x86.ActiveCfg = Release|Any CPU {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Release|x86.Build.0 = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|x64.ActiveCfg = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|x86.ActiveCfg = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|x64.ActiveCfg = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|x86.ActiveCfg = Release|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|Any CPU.Build.0 = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|x64.ActiveCfg = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|x86.ActiveCfg = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 2800167d3..32d11ff1e 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -1,8 +1,7 @@ - netcoreapp3.1;net6.0;net7.0 - net48;$(TargetFrameworks) + net7.0 false true diff --git a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj index 16fb810fc..65720028c 100644 --- a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj @@ -1,8 +1,7 @@ - netcoreapp3.1;net6.0;net7.0 - net48;$(TargetFrameworks) + net7.0 false STRONGLY_TYPED_ID_EMBED_ATTRIBUTES @@ -17,7 +16,8 @@ - + + diff --git a/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj index 38b3c43f8..b06690981 100644 --- a/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj @@ -1,8 +1,7 @@ - netcoreapp3.1;net6.0;net7.0 - net48;$(TargetFrameworks) + net7.0 false @@ -16,7 +15,8 @@ - + + diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index d7a3ed3e7..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -12,6 +12,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } @@ -140,4 +141,17 @@ writer.WriteStringValue(value.Value); } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index e7affbacb..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -12,6 +12,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } @@ -140,4 +141,17 @@ writer.WriteNumberValue(value.Value); } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 0a464e952..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -12,6 +12,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } @@ -143,4 +144,17 @@ writer.WriteNumberValue(value.Value); } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index c2c044246..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -12,6 +12,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } @@ -148,4 +149,17 @@ writer.WriteStringValue(value.Value.ToGuid()); } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index 975c29ade..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -13,6 +13,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } @@ -172,4 +173,18 @@ } } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 3e93ee6b2..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -12,6 +12,7 @@ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } @@ -158,4 +159,18 @@ writer.WriteStringValue(value.Value); } } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 229ebb021..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 0f97932a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index ea3ade611..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index f14ab3877..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 0e69fb94b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 1b4e03230..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 59db11881..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 4c1d4947a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 9ce5d9bae..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 711654ffc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index fce195165..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index fed90704a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 7d7ee092c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 90fa44401..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 2fd79a2b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 6d82a6b07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 4fabc3182..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 858205dda..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 34c44711e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 400a376b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 0606930d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 88ed2aa52..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 9c2dfd631..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 1eb3f4c2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=100_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c1d784b3a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 50aa16327..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 7abca0a14..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 771380c14..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 9ab559bb0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index e86a12a94..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 3202f6008..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 5e26639ca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index faf5c1973..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 7760b7b34..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 254b1ea77..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index b18e5d542..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index a212749a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 6abca8a56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 620c1710f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 8bf8dd26a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 3efdfa947..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index f20a57ef8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 8fa913aea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index aeda230a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt deleted file mode 100644 index c8fade53a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 6e46f01aa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 0d5185930..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 4858dd900..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=102_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 5cd6629f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 2537096c5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 86563a15b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 64aa3964a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 583ffca7f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 1d1e03578..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 23fa07284..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 7fd31a405..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 5c58cc94f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index aa75d90bd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 428f9e692..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index b860c0820..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 95a2049ba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 692c255cc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 6d04448d3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index f99fc8b1b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index cc74782c6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index afe6106de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index afe6d365e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index bbad1c5fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 847e78d87..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt deleted file mode 100644 index fb897c9bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 10c531999..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 5ea362830..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=104_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 317a1bf6c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index a9e45110f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index ee0d1dea5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 10aa0e402..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index de5067969..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 7fac279df..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 609dd414c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 3552bb9b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index c85ca7254..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index c75af94ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 46b3ade84..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 5ac620d53..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 8c5557f74..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 647dbcac3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 9c7a2f509..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 27ae17dfd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 4cfb8a161..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index ee946c796..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index c834eeb84..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 158eff403..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 7855ac9d7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt deleted file mode 100644 index cce3a3482..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt deleted file mode 100644 index e48bd4fa6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 46b8aa422..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=106_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index b5c8a5a96..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index e81138541..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 79949c17c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 8da0f4a7f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 2f30c58a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index f62caac08..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 1e2bcb601..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 944fd91dd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 533a2fad1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index a1b9e3924..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 1a3242d73..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 4210beef4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 5da86f568..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 2d50ea59f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index b60f9136c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index a2ba5c42b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index e9e229af8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 5e85b2290..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 0e0991296..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index a98851a7c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 292d71441..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 948e340b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 7bc2194ee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 633d4699c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=108_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 77a65b44c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 8187ec79d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 99b3cf5dc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index f98c47271..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index dbb8209f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 923beaffa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4cdf15814..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 611234937..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 21234322f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index dbb963bb9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 90c4c80f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 389d5fdfc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 59da85df0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 84a3a747d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 438c83476..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 2594f8cfe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 6ff9daa83..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 86c7e81c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 5fde739e4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,182 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index c017cffcb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,182 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 0b175e035..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 19624a2ce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 5a063a204..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt deleted file mode 100644 index bde4360d3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=110_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 9eb3ca3ed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 6c9819a46..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index d9a68c174..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index aaea91dc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 6e58e080f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 7a50f29a5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4d1a08f67..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 19d1cec60..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 3d126aedd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index e9a30adc1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 8362d54be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 107216968..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 72d5b09da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 16ed66311..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index b599279eb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 703b9b321..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 31e0e37b2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 5ca9449ba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index d42ec6c61..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 00b5cf617..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt deleted file mode 100644 index a54c38699..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt deleted file mode 100644 index aa0e9eae7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 69c753b1d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt deleted file mode 100644 index ba8b5b672..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=112_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 1e7c93bb3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 13d76f4ed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index f39de9f13..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 2c31f4952..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index acc106949..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 999fde6cc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 1a77ae8ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index c56f30b87..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 9ba5f1e70..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 7352fe283..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 95cb723ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 41d2e3f30..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 34585f280..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 14ea68983..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index bf93c0841..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index f62c95b9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 2f1e60a45..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index c614d8f17..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 0ffc7d313..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index a32eca9bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 1bd2d8844..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt deleted file mode 100644 index c8de7350c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 31f08a0fc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt deleted file mode 100644 index b3347986f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=114_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 9af002bb2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index a505a658a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 0a0f06c48..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 49ddfcd2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 1c50d26ed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index e07fe3197..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index f19845ca0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 36213fe29..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index cec215a8b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index ebc6df24b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 6c77e3ee4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 34ca3760a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 3d28f4c2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 0f349d3c5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 678a2da5b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 3e7667f2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 33d12a745..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index d8402738b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 6682e3e0f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index e30663635..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 2416cc823..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 2423a5d56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 74be18e21..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 8abd9f152..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=116_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 4042ccde0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 7bdff827b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 6c677e208..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 3b697d2b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 03d0c4ae5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index bc8ad6284..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index cd809a2cd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 3d0471a44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 92fe0ec82..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 975d8f384..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 59c2cc6cf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 08c22a22f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 5b2b3c8e4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index c0dd251d0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 29a78158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 3a4bc6061..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 0ee16d6f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 848042432..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 3fb771bb1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 5750c9bed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 2c4d0ce75..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 2675f6257..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt deleted file mode 100644 index eea7bb6fc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt deleted file mode 100644 index bac91705c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=118_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 656a02f85..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index df05e7bc7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index f42656289..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d93eb098f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index b8d23e1bb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 6cd419417..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4a4dc8636..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 0d233ed93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 286db9d46..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 32e9a48bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 91769108a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 4044361ba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index c4de5aea9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index eb8e6e31a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 70bf726c3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 6df6dee02..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index df972f944..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 7092ad4df..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index c86ab64a9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 5b5e53cb3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 79e03a551..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 4dac6c237..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 929da6071..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 18e4af09c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=120_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 5960ca014..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index d4037395e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 421b25aa6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 8d1909f42..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index aef61774a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 983c48f23..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 11d4927f0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 156d09c99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index de22eeb1b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 55a83a1ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index b7734820a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 59e6451b2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 547b0738d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 42de152f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 358283e03..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5fb522786..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 2a2ed1ccb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 58d287155..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 48e30a9ed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,166 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index be7bf278f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,166 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt deleted file mode 100644 index d19d15a83..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 2be3a09ac..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 540144973..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d9fa17e36..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=122_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 9ff87f22a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index ace613db4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index fa9539590..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 3500e2e01..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index c34957da1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 7b1eb108b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 2012d0001..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 1372c471d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index aa5dc7151..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 1d327d41e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 0d8564d5e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 88a8a960f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 51371beff..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 32337df1c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 75775341d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index bd59afa50..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 762634825..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 238a53262..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index ef4d5b829..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 5c427d5a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 1087be08e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt deleted file mode 100644 index ee0e3b705..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 60c0cf89d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt deleted file mode 100644 index e57b66697..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=124_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 689b279f0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index f6c64901f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 6dc1b72f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index ba9c0e587..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index b4e3b7140..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index e2e138b6c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index ea4ea86f2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 3b8f6f307..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 11f18e73f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 46bbf48d5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 6dd5202a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 38b553aa0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 28c5f159e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,167 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 07b5f09d8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,167 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 4318dfffa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,168 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 7088765e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,168 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index efc9e06b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,183 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index d577f7959..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,183 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 59bfe48fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,193 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 600fe16c4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,193 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 695aea9a2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt deleted file mode 100644 index ed406a077..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 32b3f71a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt deleted file mode 100644 index ec1a4cf85..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=126_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,172 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index db73d7c72..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index ab67db89c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 2ea30ea87..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 8947aeea4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 939d3d42b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,52 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 8a24f91e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,52 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 574bf320a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 83dbc8dea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 96e3e86ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,52 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index f027024a0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,52 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index e613f0509..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 6e94d7b9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 388416ea8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index d9055db66..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 048b12af6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 35f56493c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 2ff3dc771..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 450600ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 0b793df55..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b4ba4183a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt deleted file mode 100644 index f68abb2a5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 165f19d71..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt deleted file mode 100644 index fa395e077..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 71a1c0b0c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=64_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c37fc53b7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index dde681fe5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 6bb3bbda5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 64f4749c9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 3f1a4f562..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 063ace9a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 5c1dd8b52..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index f43621585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 5703947e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 05b15f21d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index a1a8fdc86..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 95289b405..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 1ffa1ad92..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index c1ad070c0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 59e77a8b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index f859bf143..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 6682424ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 4f423a375..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 4c40b2195..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 9a18511c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 06010874b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt deleted file mode 100644 index a656d41a4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt deleted file mode 100644 index f91464035..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 27b4ebc9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=66_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 8b5738e05..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index a36f6ecbf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index ba832c53d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 7db64fc51..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 5ca61086c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 0fca8c172..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 478074271..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d4a5de05f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 7652d3991..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 32b1783d1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 5c4676a4d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 4cfe9e512..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 14440ffb4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 662bfc751..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 85d0c0993..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 3fd9533a2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 71c9f73a4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 37d631d60..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 0686c3acf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 643a14426..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 3000297b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt deleted file mode 100644 index ce4c75fcf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 4bc54fd0f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d2ac180c7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=68_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index cb0548a8d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 8870b171b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 3d989ccd1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 25580303d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 2f9c737ac..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index b46a8788b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 814a92d5e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 5a6b204e2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 2b09b935f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index e51f2454a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index b6a171238..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 3bd9697de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index c5a2a572b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 0d9f3550b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 26e8dbfff..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 94e75fd6d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 98852f4a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index f47f6a8ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 4c036d028..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 302c77505..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt deleted file mode 100644 index fb76ae8a5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 3d72d141f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt deleted file mode 100644 index daa1ac0b9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d10c3920e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=70_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index f8930cb95..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 9414f9710..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index c05fdf6ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index a975a4ee4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 0f64b6473..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index daccd25f9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index cf7c0ec50..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 549360015..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 87bd667ff..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index fffba2829..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index fb11870e4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 77e4c13e6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index fb97bd53a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 8e9eda8b1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 341a2f8ee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5040719b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 2c109942b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index e352d9942..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 11ceeaeab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index e06b9c54a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 176023635..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt deleted file mode 100644 index db1c7c61b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt deleted file mode 100644 index f316d1479..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 306955907..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=72_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 2cc569e67..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index cadee9de5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index a64ee7c40..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index c28c5c111..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 62cc0ac1c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 353b6bd46..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 69fc7f8fd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 0bf2cfb0c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 127fa9cc2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 64e961809..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index c9cbeb718..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index dbf38da5a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index ae37d16e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 806dfbcd5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 390374254..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index bed15e33f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 7c683cfbf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 7c5f4cb29..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 6b6ddee36..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b419a8fa1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 1095a9342..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 83ecf874f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 78d15b5d9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 591ba7a5f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=74_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 01ae14b53..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index affd6aef5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index d81ef194e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 37574fcf0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index efa618f59..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 54859ce39..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index b46c13c08..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 16196024f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 432556bfc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 91a57ab9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index ec6f934cc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 0ef98800e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index e57a8b0a0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 777f4755c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 3d48388b7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 9b088f1d8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index b7f015cc4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 877f30fc1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index fe098b3a4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 97cc70861..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 40d98184f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt deleted file mode 100644 index fd6395346..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 126f4ab0b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt deleted file mode 100644 index c79e8df6f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=76_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 3790ff67e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 7c4e1343c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 51b4a4c15..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index a1268db16..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index a1cb3b7ad..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index a5b0ec3ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index f71130917..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 0946b2acc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index ebdc7c26b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index cc06de890..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 4b6b9fd2c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index b4dbcfeeb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 68189ae94..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 9245a111b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 64404d16f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 909cbea51..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 3f1013154..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 41f9a1ee8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index c0cc6719b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 42e63f7c6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 6d04e06b2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt deleted file mode 100644 index bcb489e4a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 767710b01..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 4f8df56d8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=78_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 168b818e5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 472ebf012..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 3671764de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index ac2c11dc7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 786c2b2af..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index aebcacb76..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 63135873d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d513d8f15..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index c36914d44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 7125e230d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 323d10acd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 845f7defc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 397296490..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index ec425b1ce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 4d4ab00f1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index b8acdba88..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index ab2b32ac6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 9ae7047c8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index bfa51d6d5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 1a053e670..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 0e9120a3d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 173a18603..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt deleted file mode 100644 index b9fea9451..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 859d4f1bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=80_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 0cc311720..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 137d45b60..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 11223600a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index a0f8bd739..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 80fba849c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 3db571a09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 0c60a5cae..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 7d9f21e91..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 4adee3d8a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index aa1a3a7eb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index df69a1437..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 7dd1adf15..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 31f18771c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index e4f2558b0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index a285963ee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index aab9e9198..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index aa9d7325a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 3889f1b2c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 5b5786dbc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 62660711f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 2cefad67d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 48aba8ad7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 34fcf093f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 1e9bf40ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=82_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 0b023a964..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index f83ab9759..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index c77cee59f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 92b7a8ab1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index dd10e6f39..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 6ee6a780f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index d90a5563b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 94cc48e8f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 4da96e7cb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 9a684bbf1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 0ad48235a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index e9e49454a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index ce6ce68da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index b0b9c9ddb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 3a8e23090..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 4757316fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 514e0265e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 6026081b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 7e1076586..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index f8e10771b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 39ac1ea70..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 7c17a945e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt deleted file mode 100644 index c6696416f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt deleted file mode 100644 index c4af410a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=84_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c87dcc389..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index c0c2542bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 3803ac38a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 9faf9cfb5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 6aeb853ac..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 7011b2c6e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index d2f56f074..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 4607107b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 871662de9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index c997e6643..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 852988f03..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index c62a18b7b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index c283d9fdf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 4d6886655..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index b591d94f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 7d966b94c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 9bf6ec191..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index cf5d12c3a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 1533d4e65..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index c6faeb6a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt deleted file mode 100644 index a359578f9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 082c9f619..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt deleted file mode 100644 index f21c82008..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 76fcb6e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=86_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 61db60659..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 4ca419cdf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index cef3a45e3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d689639e2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 09518e095..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 72d51729a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index b9255dda7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index fb8ec33b8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index fd4cf2b48..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 4b38bbe58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index d68e91f55..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 826898e77..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 0705ad7aa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 8d438a68c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index c292a28cd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index d24faf39f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index b1ff0bfaa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index dba667527..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index c71ac076d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index f51d952c6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt deleted file mode 100644 index cc88c8f89..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 4d4b7c7a0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 05e3a3215..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 548997e28..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=88_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 20fca5beb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 7a5b1761c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index c34371f8e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 84e55389f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index c78e15e58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index f98ea2789..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 271e0c6e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index f2f722776..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 7150263cb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 3236405d7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index c76c3fee6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 454c06db1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 40fe43481..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 291178c59..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 6d38b1a63..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 0a76879a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index bde8df3d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 688275ca4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index bb364687c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index e6853c333..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt deleted file mode 100644 index ae80c60b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt deleted file mode 100644 index f15fc930c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 0168db84c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 2eda7cd13..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=90_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 13474b97e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index f8f76f4e9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index c7e5b6c67..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d08b3d008..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 010acac36..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 8d6c4f77e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 1fe668f3d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 25a4f6dcd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 79ef7d77f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index a157f0b1a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 0ee3e6379..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 9ee6aaede..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index fa727b83b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index b453d815d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index ba58f69ce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index b6bebed58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 4785f4abd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 65b1cd404..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 67e8a47aa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 13ff4f36c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt deleted file mode 100644 index b53b89322..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 706b08e28..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 190951740..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 7701db3cd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=92_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 19dcaa007..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 1876914f2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index b0209023c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 5780d351a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 03edddb56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index cc4b7c547..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4162b32c4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 5bcc9bf93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 26f300d94..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 91d45203e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 8f0a79088..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 840d9f7cb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index ef2d7559f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 107da07c9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 26d0beffe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 2b058b982..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 325bdfdb3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,164 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 379c642c7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,164 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 702a7a499..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,174 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index cbce43d5e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,174 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt deleted file mode 100644 index f694a8854..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 2c9fa7aee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 4ccc06c79..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 8207ee2bd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=94_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 69134f044..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index ed4a9eac2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 8ebf2e466..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 2a33f94e5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 9f1bb8929..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index bb48a5b9c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 94cbf4b58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 870d679a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 56f3553c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 6f141dadf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 9a2fe4685..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 5d4cd5f9c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 20b66b657..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 832ad928e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 5479e7882..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index d98b1c9ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 686f54fa0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 206cf36d1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index c80ce25c0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index fb2c60df6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 7caa650f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 190245d93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 1c917867d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 659df3462..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=96_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index e27ab652b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 7ea62a411..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 6eb9d1a1b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 230c821fc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 27024b78f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 2e9219241..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index d1ac39f99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 344ff96d6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index ee2db7c18..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 8599b94bd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 78bac6718..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 2363589b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 5b0dfee9f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index e6363f720..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index d72018828..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 1618ac549..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index b12c7e51e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 14b09e7bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 74462001f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 577112e33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 3d8a0f3de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 7ab0c4cf1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 3792e2100..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 74e792602..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=98_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace Some.Namespace -{ - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c770901de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index a9b6264a8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index f926e3d1e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 0b4c92fd5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 7f1d75f6e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index fff29a224..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index cc026e3c5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 6f4a5a4c2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 808026446..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index c5cbf7ed3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 1e3aaca7f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 2432ff7e0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index d625fc064..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 67f890457..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 95a5bc656..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index bce3ecf72..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 81c154b52..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index d5aba85f4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 96ab789d3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 39d4fd315..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt deleted file mode 100644 index a8c8f398b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 1cc61952e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 8d044666c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt deleted file mode 100644 index f48e5fb7b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=100_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index db656b396..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index a1610c7ba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 00712b8a5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 0f2a9ad4c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 620112c63..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 191a8323a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 2a5cb4c8c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 7ef9f95e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a9a002179..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 97969f33f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index d757a27f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 216bff854..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 95246c1a9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 65814d4be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 495a250c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 1f087cc27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index ea79f6f25..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 4b1755257..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 5edf036f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 68b1539e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 26c01b319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt deleted file mode 100644 index afdfd1ab8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt deleted file mode 100644 index fa311a0c3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d48faf873..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=102_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 37f3a930c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index d65b45a40..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 07abd8d61..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index ea27671a2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 470fd8c21..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 2fbac1dc3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index eef0787ee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 765fabbd3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 81e1fe46c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index e0f50aea0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 6722dae0d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index d8c07804d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 04e676115..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index ac5232352..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 4ab683dde..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index d0d6903f9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 5694dee57..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 7361ca4a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 808fd8086..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index fe5afe261..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt deleted file mode 100644 index ef32fd2de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 3997fdf33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt deleted file mode 100644 index c90862e9e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 772074179..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=104_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 9b4ad67a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 82be04ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index e159eb253..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 8039775bc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 30cf88406..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index ceead352d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 8ca16c303..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 43391cd4a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 9fe000d10..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 83dfc5b13..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index eb491e9b9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 2b4e30e70..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 041d1c8b1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 820eac099..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 9b866b1f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 568094c3f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index dce400f11..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 46ee738ed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index ddd8806ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 6350c5a59..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 180e8bc9f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt deleted file mode 100644 index d96e9ccc6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 57ba3e078..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt deleted file mode 100644 index bd154f9dd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=106_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 6ddf400b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index edefd3e19..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 5603a7a97..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index de72a5c9f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 04d5ed600..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 492d4435b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index c2a84beaf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 1ded7de15..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index c4167cfb6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index c9bfa8705..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index fc125fe98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index fba3dc1c5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 458f874bc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 5207c1521..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 965126ffd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 73ed77a4f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 23f2bd09e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index aee381c23..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 8660e9d7d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 83bf235e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt deleted file mode 100644 index ed4edb68e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 0e2b814b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt deleted file mode 100644 index f06ad2923..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt deleted file mode 100644 index ca7781556..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=108_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 0fd446f48..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index df585294a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 667c5cc89..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 26b52565d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index f6d58a7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 26329815d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 0e15f94a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 26e1f5334..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 24f34e3c6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index ef636c428..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 5b75acd43..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index ba23aaa86..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 4ced0e5ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 4da946e03..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 2752bb172..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 084a8e3a8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 06331293f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 3c2f69cdf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index cc83142c2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,179 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index db5ac5e82..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,179 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 5beecd415..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt deleted file mode 100644 index ae2f786e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,148 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 8af0551cb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d73f249a2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=110_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,158 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 1c9d1866b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 7b4eaeabc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index afb853513..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index e77db09d6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 56b534218..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 3dd7ded00..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 8f5083824..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 8d0d182a9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index d38ab64bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index b9cea133d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 61fc5fda3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 277a1515b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index f6db63a1b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 74b66699b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 3ee11276a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 88b16635d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 9971bced7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 8afd9e40a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 85c28b6c8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index e8af45bb8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 7717dd21f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 6c953896e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 825b4476d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 1272b12ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=112_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 2c8fc1311..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index f3c8a279f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 97955ac4c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 4941d0f24..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 9c8795cbe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 848aa5a08..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 8554c6d68..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index c2731224f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 60331cebe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index c9b55ab0e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 398820d89..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 3dd2d547c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index fe0620085..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index a67503d2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 507eee32b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 06074e420..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,130 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 05a234c72..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 33520690e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 3c83a5d45..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 592e3de92..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 1284ca90a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 0479d1a06..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 8854e6396..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 1c25cd2d7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=114_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 13f927e21..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 8d6b3c9af..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 5abc28ce9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d369edd22..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 59111b2c8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 5fb4f5095..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 98f4d2293..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 27507143d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index d8ea1385e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index a28110d56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 0abaf1b7b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index ebd5436f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 25a4473a0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index c2a3842f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index f69a67c5b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 6d7e6ef17..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 38b5cfac8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 9d161984d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 9a9c606bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 859973b52..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 806629d76..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 7488db300..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt deleted file mode 100644 index c6b8ddc0a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt deleted file mode 100644 index eb8bc92a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=116_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 685405d92..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 40cc2325b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 93087a05a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 23125279d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 171009604..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 1490117c0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index fc534a9a8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 401cc1464..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index b7d1359de..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 2d94c3b3f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 0f4ee4276..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 52f4a1c49..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index d5f25ee2a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 0283fd8da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 869f91924..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 3c10251f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,151 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 73985e8ec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 9a7ea3ed2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index dc6db5368..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 0ee9510b9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 6861d19af..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 0238f6c93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,145 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 52f7a33c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 8ceec6954..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=118_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 084d3ac3d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index f89494e57..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 3f587d1f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index cc0f9ed9d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 77266d93c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index beae342f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 0575bed67..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 36d8b3a58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a3a83a353..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 21aaba3c2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index c21c615b2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index f043e3fd0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 8917fc7ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 45e111e68..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index a2f43a456..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 9ad7cdfdb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index bbdbae006..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index d6d0ae9ad..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index a8725656a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 5925895df..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,120 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 7bb7b3009..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt deleted file mode 100644 index eb0b9ab49..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 04d0406e6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 3fdda9cce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=120_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 7d9c12c06..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 11c0d87df..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 662e311b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 87e8e27e9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index cf842d0ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 65c1caded..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 257af2d9f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d7eef46f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a7fc04459..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 220ce8c14..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index e6458b418..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index db1cdf474..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 73a661a22..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 99e5a2d94..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index f1f7dcdbe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index c32d605dc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 8c80d147a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 530fe35b7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index ae75d9ec5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b016b0785..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,163 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 07c1e9e47..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 18b6ec7f2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt deleted file mode 100644 index a7fa3ad99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt deleted file mode 100644 index a6f3feb64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=122_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,149 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 5de8211b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 634ddcb1a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index ebeae45da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 50d49a9fa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 340d6fe8f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 735f180b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4d254c26f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 5873be48d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index ffde64591..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index f252ddcd1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 64506a765..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 7d8839951..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 163dbd841..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 5e3424a62..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 936523ac5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 7bbe0c166..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 46762b4f2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 00a33aaf8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 64557cefc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b73f5d29a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt deleted file mode 100644 index b50eddc31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 03327cec3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 42aefae26..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt deleted file mode 100644 index ab30ed5d0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=124_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c9d3cb337..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index e1924cb54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index d3ed07150..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index db811023f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 9ccd36e37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,156 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index bfcdbdc65..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a8664e59f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 8867bad63..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 7d40c38ad..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index a7552d21c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,164 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index f8aef1730..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,164 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 690286630..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 8fb6c4e4b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,180 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index a48d9fc5d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,180 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 19355a9b7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt deleted file mode 100644 index baa4b1fc8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 8a2c59e11..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,159 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 99281be52..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt deleted file mode 100644 index df23ecb71..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=126_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,169 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index eb78a909e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 0512da03c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 7b11ecbc4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5051c6150..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 3f60a7645..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 9469ac8d0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index e1d7cc3ad..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 69b495e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index d0484d31a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 0570e7f9e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index c9153d6f4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index de5416a37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index e77078881..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5a149d019..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index c535511a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index b3836b7f4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 32e781126..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 5e0612df0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 2326fec64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 76b51bc12..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index f25b6d0d7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 443dcf3ba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 6a4682b1e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 544aca9b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 13e33856a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 08d839444..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 88c1fced6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index a52b01b58..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt deleted file mode 100644 index cb8757bb8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt deleted file mode 100644 index b0609248e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 05e4c1d05..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index b3235218a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 9f3f52160..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 0637c8e60..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 58a185a42..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 3975bd078..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index a715a7144..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 1d07256ac..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a6802c08a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 96baacd4b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 3b11dcec0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 5f65bed3d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 707b07ae7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 41003afe8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 78ef55c9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 0f346a9e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 253b6bc1e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 0faa1a514..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 9fc762772..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index a9984641e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 7ecf175f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt deleted file mode 100644 index a5c972fdc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 5f33b8a5b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt deleted file mode 100644 index a0f6dd6b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=70_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 0026f9ab5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 4200d2be2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index bfc496515..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index bb3f5e152..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 31fd49d42..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index f3bdb9fd0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index b2a48d265..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 0fd5a829b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index f49339e9b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 7b227699c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 9b960a327..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 2cb44080d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 518bb6214..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 530792fbb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 32f4d89a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 5ed195a96..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index dcd37dcbe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 593d2953b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 843d41f35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d99ee9f12..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index e38673bc5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index ea5be926e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 8fc1ed1e0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 9afadfd66..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 1517502bc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index b52ef8fd4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 1c0f55a7d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 42014eabd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 2008244ce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index a47eff415..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 0e2732afd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 3717a90cb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt deleted file mode 100644 index ecdaa9e39..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 4b9b0f6c7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 9acc1481d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 3c8ab3e2f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=74_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c56a9a67a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 09a56302c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index e20c18bba..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 213b781dd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index fb4207785..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 131d69e89..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 22d8742b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 4f41b2a34..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index a67ace06f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index ecf396de6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 5422fccb6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 9d69e5796..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 2c371c62f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index ee1236431..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 17a5e4bfa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 00e856559..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 7cf1a2dab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index ebcc30d8d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index f6011a30b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index f75315a9c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt deleted file mode 100644 index bf795d05c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 3f679bdd7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt deleted file mode 100644 index d7ae24bee..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt deleted file mode 100644 index bb602088c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=76_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index b31cd934a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 702a14fc2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 7cd468e0b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 895fcdced..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index c9669fe9d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 828630bad..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 831970829..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 60546f0e4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 4615aa1e6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 6b23a2566..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index c583bf297..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 5497fb60d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,129 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index f48e9f6d7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index d678d9d96..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,135 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 27001c95e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index a4925f45b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 1bcb34dec..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 01b6f4f38..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 5c5f1f2c5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index d66339894..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 91f9c9590..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 5991b4275..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt deleted file mode 100644 index d6dbd113e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt deleted file mode 100644 index b846c8584..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=78_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 87be310d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index f1090968b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 94ecd3dd1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d8a5c6692..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 46b12c670..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index c2c4a296e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 3095448e4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 33f297a6b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index c99c39b37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 860616ee0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 78dd6de28..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 35bdbbfd8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 79d3bddfd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index de2fefd8b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index e240cad6d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index ca9d169e9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index ec8a5819e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 93362714b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,102 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 29dbc8350..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index d1ee19da1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index e4dddd8bc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 9c1b9888c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 900772d34..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index d01d1f1bb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 81d79c37c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 6458fb752..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index a35106bda..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 18657f8db..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 66675bbeb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 5861025d0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index d69f00155..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 87c10ef89..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt deleted file mode 100644 index c350aca6b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt deleted file mode 100644 index e815662a0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,108 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt deleted file mode 100644 index ba4ad5cfa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 54d8fd55c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=82_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index c53bdacbe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 1da29732f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 17658fee7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 27c228fce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 33fd76a2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 5973a811e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 8293a9b69..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index f9fc3a98c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 992e03701..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 12223faf9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index b4f807376..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 186f3dd01..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 29b35be43..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 08a3d45ce..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index b19cb0067..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5657ffacd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index e360395f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 56a4a03f7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 1ce4b2b03..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 2752fad2d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,107 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 8790eda6f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt deleted file mode 100644 index b8979c0b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 4d9565758..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt deleted file mode 100644 index f3d26701f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=84_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,100 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index ee737930b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index b531a492b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 05f0eda56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index af214684a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 7b31167ea..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 8e4f27bd8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,123 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 34c2a6229..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 86e2dc23e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index e92132df7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 009048bd9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index faaec318a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 5daa4f3b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index d53e4ca2d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 210035038..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 576d03e5a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 1775d37b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,133 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 41c86271e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 3cc8744f9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index bb7d4191e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 481431824..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 6787f464b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt deleted file mode 100644 index def7b7ff4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 244098a07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 5f477a859..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=86_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 1b47d2cdc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 4b744040c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index f7ea38f7c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 9e307a24e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 64796958b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index cbbe29499..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 0dbb0c8fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index c96e15c39..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 1e7709545..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 9460bb27b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index b5165576b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 279037442..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index bf3f59d14..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 782c38adf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 90e4680a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 9e4678ea7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 1dc3712c8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index ed7bae957..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 735b48c9d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index bc1630e85..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt deleted file mode 100644 index eb5c805fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 16ac1095b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 5ba5e3bbf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 1cfa95d85..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=88_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 208ec93c3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 8f185a4f3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index fe284d007..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 1a46b1ea2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 3745d9798..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index c47524526..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,116 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 149b45a2e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index a97e183fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index ceb58b565..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 6b44762bc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index c883b9be5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 7fa6b51fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index ff76f547c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index e51eafe88..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 47c826ce2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 994f1ec31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 1ac0d5121..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 76822e596..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index a7eb745c4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 519f9aa82..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 6e4bf7b93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 670bd147a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt deleted file mode 100644 index b593cf637..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 5e33639dc..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=90_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,132 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 356154d78..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index b86125afd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index ca80b62b6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index f6d2fe3d0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index d58e49e2a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 9056b5935..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 4fe7970b7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 21b1e2184..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 8a3737cb5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index ad21ccf06..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 29e1d7b7c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 57961b962..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 0b9436d70..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index d61b7fbe2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,96 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 468548353..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 5c90fb22e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index f30324371..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index 9bb26ff98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index f8b797795..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 7f6dcc442..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 55e959b56..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 088047efe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 31b378a2a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt deleted file mode 100644 index d61090972..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=92_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index ff1f2bcfa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index e428caf34..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 552339ad5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index 71d793ab8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 45bbc173a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 00d558c29..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,137 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index f7aa6b88a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index e85034bb7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 30c7b6e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index 7e4555a75..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,139 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 25ee30f9e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 2b07a0f95..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index 4a2d06fe7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index f206a3939..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 86deeb44d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index def904cb4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 5d04a3df8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index e9267cb05..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,161 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 7b65964a4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,171 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 885d7aca0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,171 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt deleted file mode 100644 index cf5d603df..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt deleted file mode 100644 index 53e19cbac..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,142 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 0ffdbf6e8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt deleted file mode 100644 index f51444ab3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=94_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index bb46a843a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d210adb0d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index e1da0f039..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index 5405ca9e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index eaffadd51..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 391dd15b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index f0573869f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 4db8cff26..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index d6e8df674..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 19e583761..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,88 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt deleted file mode 100644 index fbd695fd5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt deleted file mode 100644 index fce430505..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt deleted file mode 100644 index 13c35649c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt deleted file mode 100644 index 844aae323..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt deleted file mode 100644 index 1b1a7571e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=4.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt deleted file mode 100644 index d71eddf41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Guid_implementations=6.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt deleted file mode 100644 index 50dd4997e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=0.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt deleted file mode 100644 index 0f5a4c6b4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=2.verified.txt +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt deleted file mode 100644 index 989973936..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=4.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt deleted file mode 100644 index aa4e9b886..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Int_implementations=6.verified.txt +++ /dev/null @@ -1,111 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt deleted file mode 100644 index 9608d512b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=0.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt deleted file mode 100644 index b5e7ea476..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=2.verified.txt +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt deleted file mode 100644 index 764c960db..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=4.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt deleted file mode 100644 index 05431e594..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=Long_implementations=6.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt deleted file mode 100644 index ab5f9a4b3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=0.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt deleted file mode 100644 index 7d3108bd5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=2.verified.txt +++ /dev/null @@ -1,118 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt deleted file mode 100644 index 83ef853fe..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=4.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt deleted file mode 100644 index 398bb92af..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=MassTransitNewId_implementations=6.verified.txt +++ /dev/null @@ -1,119 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt deleted file mode 100644 index 889795c39..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=0.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt deleted file mode 100644 index e3fa6b90f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=2.verified.txt +++ /dev/null @@ -1,121 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt deleted file mode 100644 index 338323c10..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=4.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt deleted file mode 100644 index 41754a740..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=NullableString_implementations=6.verified.txt +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt deleted file mode 100644 index 8200d519e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=0.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt deleted file mode 100644 index f84353ae2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=2.verified.txt +++ /dev/null @@ -1,114 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt deleted file mode 100644 index 519454c49..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=4.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt deleted file mode 100644 index 939bef016..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=98_backingType=String_implementations=6.verified.txt +++ /dev/null @@ -1,124 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt index adb0efa71..0d618f5be 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public System.Guid Value { get; } @@ -53,17 +52,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt index 4e5a7881e..dc3548e2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Guid_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public System.Guid Value { get; } @@ -52,17 +51,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt index ec97309e7..218054f51 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public System.Guid Value { get; } @@ -46,17 +45,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 72% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt index 053251f0b..bd295d6c1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Guid_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public System.Guid Value { get; } @@ -45,17 +44,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt index 80b182278..420ee5f2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public System.Guid Value { get; } @@ -56,17 +55,4 @@ return guid.HasValue ? new MyTestId(guid.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt index a59540425..87420f08f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Guid_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public System.Guid Value { get; } @@ -55,17 +54,4 @@ return guid.HasValue ? new MyTestId(guid.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Guid_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt index 5b4bc511c..864fdcaed 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public System.Guid Value { get; } @@ -49,17 +48,4 @@ writer.WriteStringValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt index f82e44dc2..035d403a7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Guid_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public System.Guid Value { get; } @@ -48,17 +47,4 @@ writer.WriteStringValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt index 40b90d254..14b9c5b84 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public System.Guid Value { get; } @@ -77,17 +76,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt index e84440901..0077e4022 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Guid_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public System.Guid Value { get; } @@ -76,17 +75,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt index 2eb0b902b..b9fcc345d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public int Value { get; } @@ -53,17 +52,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt index c602db1c1..3d3dbec95 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Int_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public int Value { get; } @@ -52,17 +51,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 71% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt index df51aa2d2..3ad892329 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public int Value { get; } @@ -45,17 +44,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 71% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt index 860d11d16..57b00caf5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Int_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public int Value { get; } @@ -44,17 +43,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt index d50562489..2da11bf8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public int Value { get; } @@ -55,17 +54,4 @@ return result.HasValue ? new MyTestId(result.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt index 2fabf6ec3..5dec9d086 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Int_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public int Value { get; } @@ -54,17 +53,4 @@ return result.HasValue ? new MyTestId(result.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Int_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt index 6eaf84341..a8887e507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public int Value { get; } @@ -48,17 +47,4 @@ writer.WriteNumberValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt index 9e5aa01e5..398c4983b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Int_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public int Value { get; } @@ -47,17 +46,4 @@ writer.WriteNumberValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt similarity index 81% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt index b52ee1b64..8ce140c59 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public int Value { get; } @@ -76,17 +75,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt similarity index 81% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt index 4e7eabcb7..7f290a4bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Int_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public int Value { get; } @@ -75,17 +74,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt index ac15b8ad9..8c4c6b8ca 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public long Value { get; } @@ -54,17 +53,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt index 02364d284..bf29f0632 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=Long_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public long Value { get; } @@ -53,17 +52,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 72% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt index 653f68548..a745c3f85 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public long Value { get; } @@ -45,17 +44,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 71% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt index 7612bcd89..57a90b071 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=Long_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public long Value { get; } @@ -44,17 +43,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt index 33c007457..5e6714afd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public long Value { get; } @@ -55,17 +54,4 @@ return result.HasValue ? new MyTestId(result.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt index b8b4ec715..a3ab351fb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=Long_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public long Value { get; } @@ -54,17 +53,4 @@ return result.HasValue ? new MyTestId(result.Value) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=Long_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt index 682c30132..323a04ec0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public long Value { get; } @@ -48,17 +47,4 @@ writer.WriteNumberValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt index f4cfe82a2..7f65e548d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=Long_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public long Value { get; } @@ -47,17 +46,4 @@ writer.WriteNumberValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt index 0741749dd..bb00244bd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public long Value { get; } @@ -78,17 +77,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt index 6f34ff803..e59f029cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=Long_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public long Value { get; } @@ -77,17 +76,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt index 2ccf8ab8b..e52a905ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public MassTransit.NewId Value { get; } @@ -53,17 +52,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt index 6a54390d3..5a4844ff5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=MassTransitNewId_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public MassTransit.NewId Value { get; } @@ -52,17 +51,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt index dd6a5b2d9..27986a9f0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public MassTransit.NewId Value { get; } @@ -46,17 +45,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt index fb8614773..a19ae7602 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=MassTransitNewId_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public MassTransit.NewId Value { get; } @@ -45,17 +44,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 77% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt index 67fdc8a22..e42ad1a59 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public MassTransit.NewId Value { get; } @@ -56,17 +55,4 @@ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt index 2736c805d..0f26b0e78 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=MassTransitNewId_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public MassTransit.NewId Value { get; } @@ -55,17 +54,4 @@ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=MassTransitNewId_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt index 1cb9c7fe4..a1a6faa50 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public MassTransit.NewId Value { get; } @@ -49,17 +48,4 @@ writer.WriteStringValue(value.Value.ToGuid()); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt index 136994015..31d84c7b2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=MassTransitNewId_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public MassTransit.NewId Value { get; } @@ -48,17 +47,4 @@ writer.WriteStringValue(value.Value.ToGuid()); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt similarity index 84% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt index cf3b8f92c..8815c1a53 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public MassTransit.NewId Value { get; } @@ -85,17 +84,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt similarity index 84% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt index 2c23fa4a7..2e3626019 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=MassTransitNewId_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public MassTransit.NewId Value { get; } @@ -84,17 +83,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 77% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt index 43c277ec4..8e82c6b0a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string? Value { get; } @@ -71,18 +70,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt index e2f3c748f..aad0a6a09 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=NullableString_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string? Value { get; } @@ -61,18 +60,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt index 4a3ccb0a6..32d805c45 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string? Value { get; } @@ -63,18 +62,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 72% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt index 7401046fe..8c854d1d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=NullableString_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string? Value { get; } @@ -53,18 +52,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 79% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt index fa37927fd..e1854a2a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string? Value { get; } @@ -79,18 +78,4 @@ return new MyTestId(serializer.Deserialize(reader)); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 77% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt index 20ffb058b..c60dab4e5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=NullableString_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string? Value { get; } @@ -69,18 +68,4 @@ return new MyTestId(serializer.Deserialize(reader)); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=NullableString_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt similarity index 78% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt index 58428a273..b8035d08e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string? Value { get; } @@ -73,18 +72,4 @@ } } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt index 46ab7dd26..27b0a2df2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=NullableString_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string? Value { get; } @@ -63,18 +62,4 @@ } } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt index b80fbbe06..fe59fe488 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string? Value { get; } @@ -95,18 +94,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt similarity index 81% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt index 7fceabbcd..9998098e1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=NullableString_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt @@ -11,7 +11,6 @@ #nullable enable [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string? Value { get; } @@ -85,18 +84,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt index 24f00de86..e578dc79d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string Value { get; } @@ -69,18 +68,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt index a0b5e9259..b02959a47 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=96_backingType=String_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string Value { get; } @@ -59,18 +58,4 @@ }; } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt similarity index 75% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt index e3440de53..d6b9b51b1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string Value { get; } @@ -63,18 +62,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt similarity index 73% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt index aa5f92335..434501443 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=80_backingType=String_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt @@ -9,7 +9,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string Value { get; } @@ -53,18 +52,4 @@ mappingHints ) { } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt similarity index 78% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt index 0ef09c5a1..9ab6e43fa 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string Value { get; } @@ -69,21 +68,14 @@ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) { - return new MyTestId(serializer.Deserialize(reader)); - } - } + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); } } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt index da5ba8ad0..7f3dfff34 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=68_backingType=String_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string Value { get; } @@ -59,21 +58,14 @@ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) { - return new MyTestId(serializer.Deserialize(reader)); - } - } + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); } } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=64_backingType=String_implementations=0.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt similarity index 76% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt index 4f6ffcaef..0b2bca560 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string Value { get; } @@ -66,18 +65,4 @@ writer.WriteStringValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt similarity index 74% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt index 3ec1879f2..a250192a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=72_backingType=String_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string Value { get; } @@ -56,18 +55,4 @@ writer.WriteStringValue(value.Value); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt similarity index 82% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt index dc4ca2ba4..18075710c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=4.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IComparable { public string Value { get; } @@ -90,18 +89,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt similarity index 80% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt index 780a17158..d494488e1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=_converter=66_backingType=String_implementations=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt @@ -10,7 +10,6 @@ #pragma warning disable 1591 // publicly visible type or member must be documented [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] readonly partial struct MyTestId : System.IEquatable { public string Value { get; } @@ -80,18 +79,4 @@ return base.ConvertTo(context, culture, value, destinationType); } } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index e397007be..9800a32ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 0b021b89a..cf0b59cc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 0b021b89a..cf0b59cc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 1be7dd3cb..ae10a54b7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index a7e3384bc..fbb9ed982 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index e8ca99b42..7de59eb4c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 62ccb4765..5a9b9674e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index af074ad91..ea0fbaa4c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 1be7dd3cb..ae10a54b7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index a7e3384bc..fbb9ed982 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index e8ca99b42..7de59eb4c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 62ccb4765..5a9b9674e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index af074ad91..ea0fbaa4c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index 7e73d73fe..bbd3238f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index c259d55ac..478076d59 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index ebcdb6716..78053d0fe 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index 02e7314d4..cdba9ab50 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -173,6 +173,12 @@ namespace StronglyTypedIds /// Creates a Dapper TypeHandler for converting to and from the type /// DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + } } #endif diff --git a/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs b/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs index 383b9a129..8d0a157e1 100644 --- a/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs +++ b/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs @@ -153,15 +153,14 @@ public static IEnumerable Parameters() // All individual convert types foreach (var converter in EnumHelper.AllConverters(includeDefault: false)) { - yield return new object[] { backingType, converter, StronglyTypedIdImplementations.None }; - } - // All individual implementations - foreach (var implementation in EnumHelper.AllImplementations(includeDefault: false)) - { - yield return new object[] { backingType, StronglyTypedIdConverter.None, implementation }; + // All individual implementations + foreach (var implementation in EnumHelper.AllImplementations(includeDefault: false)) + { + yield return new object[] { backingType, converter, implementation }; + } } } } } -} \ No newline at end of file +} diff --git a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj index 4fc7f0fb2..9f6d4f4a7 100644 --- a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj +++ b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj @@ -1,8 +1,7 @@  - netcoreapp3.1;net6.0;net7.0 - net48;$(TargetFrameworks) + net7.0 false latest From c3b53b7aeffe6d14c1dc2be4446afa1b532ab272 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 16:53:10 +0300 Subject: [PATCH 03/37] 0.007 --- src/StronglyTypedIds/StronglyTypedIds.csproj | 4 ++-- version.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/StronglyTypedIds/StronglyTypedIds.csproj b/src/StronglyTypedIds/StronglyTypedIds.csproj index 64f63c39f..b3cd8e94d 100644 --- a/src/StronglyTypedIds/StronglyTypedIds.csproj +++ b/src/StronglyTypedIds/StronglyTypedIds.csproj @@ -4,7 +4,7 @@ netstandard2.0 false enable - StronglyTypedId + Tennisi.StronglyTypedId A source generator for creating strongly-typed IDs by decorating with a [StronglyTypedId] attribute @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/version.props b/version.props index 5ecc41198..4ab397a63 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 1.0.0 - beta06 + beta07 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From ba4a1e2a68eed6df09ef9a26c6157a52c303ce96 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 16:53:10 +0300 Subject: [PATCH 04/37] 0.007 --- Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 54c03fcd5..a879488ad 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,9 +10,9 @@ false MIT logo.png - https://github.com/andrewlock/StronglyTypedId + https://github.com/tennisi/StronglyTypedId stronglytypedid attribute generator generation codegen codegenerator codegeneration netescapades - https://github.com/andrewlock/StronglyTypedId + https://github.com/tennisi/StronglyTypedId git false @@ -42,4 +42,4 @@ - \ No newline at end of file + From 8c4d3b9c97e197186723f892e2757ffc6a307177 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 17:02:58 +0300 Subject: [PATCH 05/37] ubuntu-latest --- .github/workflows/BuildAndPack.yml | 120 ++++++++++++++--------------- StronglyTypedId.sln | 1 + 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/.github/workflows/BuildAndPack.yml b/.github/workflows/BuildAndPack.yml index cdd141ece..d01eb547b 100644 --- a/.github/workflows/BuildAndPack.yml +++ b/.github/workflows/BuildAndPack.yml @@ -58,63 +58,63 @@ jobs: with: name: artifacts path: artifacts - windows-latest: - name: windows-latest - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 7.0.x - 6.0.x - 5.0.x - 3.1.x - - name: Cache .nuke/temp, ~/.nuget/packages - uses: actions/cache@v2 - with: - path: | - .nuke/temp - ~/.nuget/packages - !~/.nuget/packages/stronglytypeid - key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }} - - name: Run './build.cmd Clean Test TestPackages PushToNuGet' - run: ./build.cmd Clean Test TestPackages PushToNuGet - env: - GithubToken: ${{ secrets.GITHUB_TOKEN }} - NuGetToken: ${{ secrets.NUGET_TOKEN }} - MSBuildEnableWorkloadResolver: false - - uses: actions/upload-artifact@v1 - with: - name: artifacts - path: artifacts - macOS-latest: - name: macOS-latest - runs-on: macOS-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 7.0.x - 6.0.x - 5.0.x - 3.1.x - - name: Cache .nuke/temp, ~/.nuget/packages - uses: actions/cache@v2 - with: - path: | - .nuke/temp - ~/.nuget/packages - !~/.nuget/packages/stronglytypeid - key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }} - - name: Run './build.cmd Clean Test TestPackages PushToNuGet' - run: ./build.cmd Clean Test TestPackages PushToNuGet - env: - GithubToken: ${{ secrets.GITHUB_TOKEN }} - NuGetToken: ${{ secrets.NUGET_TOKEN }} - MSBuildEnableWorkloadResolver: false - - uses: actions/upload-artifact@v1 - with: - name: artifacts - path: artifacts +# windows-latest: +# name: windows-latest +# runs-on: windows-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-dotnet@v3 +# with: +# dotnet-version: | +# 7.0.x +# 6.0.x +# 5.0.x +# 3.1.x +# - name: Cache .nuke/temp, ~/.nuget/packages +# uses: actions/cache@v2 +# with: +# path: | +# .nuke/temp +# ~/.nuget/packages +# !~/.nuget/packages/stronglytypeid +# key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }} +# - name: Run './build.cmd Clean Test TestPackages PushToNuGet' +# run: ./build.cmd Clean Test TestPackages PushToNuGet +# env: +# GithubToken: ${{ secrets.GITHUB_TOKEN }} +# NuGetToken: ${{ secrets.NUGET_TOKEN }} +# MSBuildEnableWorkloadResolver: false +# - uses: actions/upload-artifact@v1 +# with: +# name: artifacts +# path: artifacts +# macOS-latest: +# name: macOS-latest +# runs-on: macOS-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-dotnet@v3 +# with: +# dotnet-version: | +# 7.0.x +# 6.0.x +# 5.0.x +# 3.1.x +# - name: Cache .nuke/temp, ~/.nuget/packages +# uses: actions/cache@v2 +# with: +# path: | +# .nuke/temp +# ~/.nuget/packages +# !~/.nuget/packages/stronglytypeid +# key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }} +# - name: Run './build.cmd Clean Test TestPackages PushToNuGet' +# run: ./build.cmd Clean Test TestPackages PushToNuGet +# env: +# GithubToken: ${{ secrets.GITHUB_TOKEN }} +# NuGetToken: ${{ secrets.NUGET_TOKEN }} +# MSBuildEnableWorkloadResolver: false +# - uses: actions/upload-artifact@v1 +# with: +# name: artifacts +# path: artifacts diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index e61f35fd7..a4d2a6c5c 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md releasenotes.props = releasenotes.props version.props = version.props + .github\workflows\BuildAndPack.yml = .github\workflows\BuildAndPack.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" From bbfbcc447055db032b7ffbf4a413f6a27533c347 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 17:11:30 +0300 Subject: [PATCH 06/37] Minus reference --- .../StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj index 65720028c..3460f685f 100644 --- a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj @@ -17,7 +17,7 @@ - + From 9e6c5f403d93bfacb3fd116a365febe31eda0416 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 17:24:44 +0300 Subject: [PATCH 07/37] references --- StronglyTypedId.sln | 2 ++ .../StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index a4d2a6c5c..4342eaef6 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution releasenotes.props = releasenotes.props version.props = version.props .github\workflows\BuildAndPack.yml = .github\workflows\BuildAndPack.yml + CHANGELOG.md = CHANGELOG.md + build.sh = build.sh EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" diff --git a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj index 3460f685f..b06690981 100644 --- a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj @@ -3,7 +3,6 @@ net7.0 false - STRONGLY_TYPED_ID_EMBED_ATTRIBUTES @@ -17,7 +16,7 @@ - + From 71f123ebb680b5f134e2b2079ac782903f583386 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 17:51:50 +0300 Subject: [PATCH 08/37] temp --- StronglyTypedId.sln | 1 + build/Build.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index 4342eaef6..3f56b4858 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .github\workflows\BuildAndPack.yml = .github\workflows\BuildAndPack.yml CHANGELOG.md = CHANGELOG.md build.sh = build.sh + NuGet.integration-tests.config = NuGet.integration-tests.config EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" diff --git a/build/Build.cs b/build/Build.cs index 39bb2c919..43c63a6c0 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -146,7 +146,7 @@ class Build : NukeBuild Target PushToNuGet => _ => _ .DependsOn(Compile) - .OnlyWhenStatic(() => IsTag && IsServerBuild && IsWin) + .OnlyWhenStatic(() => true || ( IsTag && IsServerBuild && IsWin )) .Requires(() => NuGetToken) .After(Pack) .Executes(() => From 17e24fce36c1babf7d1726f5465f33eee9fa2e8e Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 7 Mar 2023 19:27:21 +0300 Subject: [PATCH 09/37] Tests Fix --- ...pperTypeHandler_i=IComparable.verified.txt | 55 ----------- ...apperTypeHandler_i=IEquatable.verified.txt | 54 ----------- ...eValueConverter_i=IComparable.verified.txt | 48 --------- ...reValueConverter_i=IEquatable.verified.txt | 47 --------- ...=NewtonsoftJson_i=IComparable.verified.txt | 58 ----------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 57 ----------- ...gerSchemaFilter_i=IComparable.verified.txt | 51 ---------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 50 ---------- ...=SystemTextJson_i=IComparable.verified.txt | 51 ---------- ...c=SystemTextJson_i=IEquatable.verified.txt | 50 ---------- ...c=TypeConverter_i=IComparable.verified.txt | 79 --------------- ..._c=TypeConverter_i=IEquatable.verified.txt | 78 --------------- ...pperTypeHandler_i=IComparable.verified.txt | 55 ----------- ...apperTypeHandler_i=IEquatable.verified.txt | 54 ----------- ...eValueConverter_i=IComparable.verified.txt | 47 --------- ...reValueConverter_i=IEquatable.verified.txt | 46 --------- ...=NewtonsoftJson_i=IComparable.verified.txt | 57 ----------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 56 ----------- ...gerSchemaFilter_i=IComparable.verified.txt | 50 ---------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 49 ---------- ...=SystemTextJson_i=IComparable.verified.txt | 50 ---------- ...c=SystemTextJson_i=IEquatable.verified.txt | 49 ---------- ...c=TypeConverter_i=IComparable.verified.txt | 78 --------------- ..._c=TypeConverter_i=IEquatable.verified.txt | 77 --------------- ...pperTypeHandler_i=IComparable.verified.txt | 56 ----------- ...apperTypeHandler_i=IEquatable.verified.txt | 55 ----------- ...eValueConverter_i=IComparable.verified.txt | 47 --------- ...reValueConverter_i=IEquatable.verified.txt | 46 --------- ...=NewtonsoftJson_i=IComparable.verified.txt | 57 ----------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 56 ----------- ...gerSchemaFilter_i=IComparable.verified.txt | 50 ---------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 49 ---------- ...=SystemTextJson_i=IComparable.verified.txt | 50 ---------- ...c=SystemTextJson_i=IEquatable.verified.txt | 49 ---------- ...c=TypeConverter_i=IComparable.verified.txt | 80 --------------- ..._c=TypeConverter_i=IEquatable.verified.txt | 79 --------------- ...pperTypeHandler_i=IComparable.verified.txt | 55 ----------- ...apperTypeHandler_i=IEquatable.verified.txt | 54 ----------- ...eValueConverter_i=IComparable.verified.txt | 48 --------- ...reValueConverter_i=IEquatable.verified.txt | 47 --------- ...=NewtonsoftJson_i=IComparable.verified.txt | 58 ----------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 57 ----------- ...gerSchemaFilter_i=IComparable.verified.txt | 51 ---------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 50 ---------- ...=SystemTextJson_i=IComparable.verified.txt | 51 ---------- ...c=SystemTextJson_i=IEquatable.verified.txt | 50 ---------- ...c=TypeConverter_i=IComparable.verified.txt | 87 ----------------- ..._c=TypeConverter_i=IEquatable.verified.txt | 86 ---------------- ...pperTypeHandler_i=IComparable.verified.txt | 73 -------------- ...apperTypeHandler_i=IEquatable.verified.txt | 63 ------------ ...eValueConverter_i=IComparable.verified.txt | 65 ------------- ...reValueConverter_i=IEquatable.verified.txt | 55 ----------- ...=NewtonsoftJson_i=IComparable.verified.txt | 81 ---------------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 71 -------------- ...gerSchemaFilter_i=IComparable.verified.txt | 69 ------------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 59 ----------- ...=SystemTextJson_i=IComparable.verified.txt | 75 -------------- ...c=SystemTextJson_i=IEquatable.verified.txt | 65 ------------- ...c=TypeConverter_i=IComparable.verified.txt | 97 ------------------- ..._c=TypeConverter_i=IEquatable.verified.txt | 87 ----------------- ...pperTypeHandler_i=IComparable.verified.txt | 71 -------------- ...apperTypeHandler_i=IEquatable.verified.txt | 61 ------------ ...eValueConverter_i=IComparable.verified.txt | 65 ------------- ...reValueConverter_i=IEquatable.verified.txt | 55 ----------- ...=NewtonsoftJson_i=IComparable.verified.txt | 81 ---------------- ...c=NewtonsoftJson_i=IEquatable.verified.txt | 71 -------------- ...gerSchemaFilter_i=IComparable.verified.txt | 69 ------------- ...ggerSchemaFilter_i=IEquatable.verified.txt | 59 ----------- ...=SystemTextJson_i=IComparable.verified.txt | 68 ------------- ...c=SystemTextJson_i=IEquatable.verified.txt | 58 ----------- ...c=TypeConverter_i=IComparable.verified.txt | 92 ------------------ ..._c=TypeConverter_i=IEquatable.verified.txt | 82 ---------------- .../SourceGenerationHelperSnapshotTests.cs | 11 ++- 73 files changed, 6 insertions(+), 4411 deletions(-) delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index 0d618f5be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index dc3548e2a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index 218054f51..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index bd295d6c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index 420ee5f2d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index 87420f08f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index 4d008c0a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index 670eb0934..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index 864fdcaed..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index 035d403a7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index 14b9c5b84..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index 0077e4022..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index b9fcc345d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index 3d3dbec95..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index 3ad892329..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index 57b00caf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index 2da11bf8f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index 5dec9d086..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index 463572661..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index 21b391fb9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index a8887e507..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index 398c4983b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index 8ce140c59..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index 7f290a4bf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index 8c4c6b8ca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index bf29f0632..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index a745c3f85..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index 57a90b071..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index 5e6714afd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index a3ab351fb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index c510138aa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index a5c84d000..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index 323a04ec0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index 7f65e548d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index bb00244bd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index e59f029cf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index e52a905ae..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index 5a4844ff5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index 27986a9f0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index a19ae7602..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index e42ad1a59..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index 0f26b0e78..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index 91ddf1698..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index ff5b17479..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index a1a6faa50..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index 31d84c7b2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index 8815c1a53..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index 2e3626019..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index 8e82c6b0a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index aad0a6a09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index 32d805c45..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index 8c854d1d6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index e1854a2a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index c60dab4e5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index f935efe07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index f67d13721..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index b8035d08e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,75 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index 27b0a2df2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index fe59fe488..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index 9998098e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt deleted file mode 100644 index e578dc79d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IComparable.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt deleted file mode 100644 index b02959a47..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=IEquatable.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt deleted file mode 100644 index d6b9b51b1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt deleted file mode 100644 index 434501443..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt deleted file mode 100644 index 9ab6e43fa..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IComparable.verified.txt +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt deleted file mode 100644 index 7f3dfff34..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt deleted file mode 100644 index 11bd8e0d9..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IComparable.verified.txt +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt deleted file mode 100644 index 9e717ee91..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=IEquatable.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt deleted file mode 100644 index 0b2bca560..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IComparable.verified.txt +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt deleted file mode 100644 index a250192a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=IEquatable.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt deleted file mode 100644 index 18075710c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IComparable.verified.txt +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt deleted file mode 100644 index d494488e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=IEquatable.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs b/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs index 8d0a157e1..b05237321 100644 --- a/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs +++ b/test/StronglyTypedIds.Tests/SourceGenerationHelperSnapshotTests.cs @@ -153,12 +153,13 @@ public static IEnumerable Parameters() // All individual convert types foreach (var converter in EnumHelper.AllConverters(includeDefault: false)) { + yield return new object[] { backingType, converter, StronglyTypedIdImplementations.None }; + } - // All individual implementations - foreach (var implementation in EnumHelper.AllImplementations(includeDefault: false)) - { - yield return new object[] { backingType, converter, implementation }; - } + // All individual implementations + foreach (var implementation in EnumHelper.AllImplementations(includeDefault: false).Where(a=> a != StronglyTypedIdImplementations.None)) + { + yield return new object[] { backingType, StronglyTypedIdConverter.None, implementation }; } } } From bd3a80c43a75444fa30b6e357ee39c6b0b017916 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 13:30:32 +0300 Subject: [PATCH 10/37] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StronglyTypedIds.IntegrationTests.csproj | 3 ++- ...ronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj | 7 ++++--- .../StronglyTypedIds.Nuget.IntegrationTests.csproj | 6 +++--- test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 32d11ff1e..2800167d3 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -1,7 +1,8 @@ - net7.0 + netcoreapp3.1;net6.0;net7.0 + net48;$(TargetFrameworks) false true diff --git a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj index b06690981..17a628451 100644 --- a/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.Attributes.IntegrationTests/StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj @@ -1,8 +1,10 @@ - net7.0 + netcoreapp3.1;net6.0;net7.0 + net48;$(TargetFrameworks) false + STRONGLY_TYPED_ID_EMBED_ATTRIBUTES @@ -15,8 +17,7 @@ - - + diff --git a/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj b/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj index b06690981..4747ca652 100644 --- a/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj +++ b/test/StronglyTypedIds.Nuget.IntegrationTests/StronglyTypedIds.Nuget.IntegrationTests.csproj @@ -1,7 +1,8 @@ - net7.0 + netcoreapp3.1;net6.0;net7.0 + net48;$(TargetFrameworks) false @@ -15,8 +16,7 @@ - - + diff --git a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj index 9f6d4f4a7..4fc7f0fb2 100644 --- a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj +++ b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj @@ -1,7 +1,8 @@  - net7.0 + netcoreapp3.1;net6.0;net7.0 + net48;$(TargetFrameworks) false latest From 641e7953c5a8e73c007b7febf6b2bc9a86d86dac Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 13:36:34 +0300 Subject: [PATCH 11/37] version/nullable --- .../StronglyTypedIds.IntegrationTests.csproj | 1 + version.props | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 2800167d3..8909346e3 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -4,6 +4,7 @@ netcoreapp3.1;net6.0;net7.0 net48;$(TargetFrameworks) false + enable true diff --git a/version.props b/version.props index 4ab397a63..f335c5f32 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 1.0.0 - beta07 + 1.0.1 + beta $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 57a79b8df47c676606881cb2f49781c5a4626727 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 13:40:30 +0300 Subject: [PATCH 12/37] version --- version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.props b/version.props index f335c5f32..992754da0 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 1.0.1 - beta + 1.0.0 + beta08 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 23599fe4883bcab08c2e5ff794c672f84c232113 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 13:42:48 +0300 Subject: [PATCH 13/37] version --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 992754da0..31ac3894a 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ 1.0.0 - beta08 + beta-08 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 742e3ba79f2d134f0b08d5738fb06ffcf30e60a6 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 13:54:05 +0300 Subject: [PATCH 14/37] change version --- version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.props b/version.props index 31ac3894a..abf34b4ae 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 1.0.0 - beta-08 + 1.0.1 + $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 079d098d64a2d49cee05485bf2eec0e9b14a146f Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 14:00:29 +0300 Subject: [PATCH 15/37] version --- StronglyTypedId.sln | 2 -- 1 file changed, 2 deletions(-) diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index 3f56b4858..81f0a188c 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -105,14 +105,12 @@ Global {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Release|x86.ActiveCfg = Release|Any CPU {F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Release|x86.Build.0 = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|x64.ActiveCfg = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Debug|x86.ActiveCfg = Debug|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|x64.ActiveCfg = Release|Any CPU {A7355210-7DDC-4968-84B7-79002113EA6E}.Release|x86.ActiveCfg = Release|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|Any CPU.Build.0 = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|x64.ActiveCfg = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Debug|x86.ActiveCfg = Debug|Any CPU {19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}.Release|Any CPU.ActiveCfg = Release|Any CPU From 769c6cb5fefd690da0221d048772f032037b2bb6 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 15:37:08 +0300 Subject: [PATCH 16/37] Parsable --- .../StronglyTypedIdImplementations.cs | 9 ++++++++- src/StronglyTypedIds/SourceGenerationHelper.cs | 10 ++++++++-- src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs | 10 ++++++++++ src/StronglyTypedIds/Templates/Int/Int_Parsable.cs | 10 ++++++++++ src/StronglyTypedIds/Templates/Long/Long_Parsable.cs | 10 ++++++++++ src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs | 10 ++++++++++ .../NullableString/NullableString_Parsable.cs | 10 ++++++++++ .../Templates/String/String_Parsable.cs | 10 ++++++++++ .../StronglyTypedIds.IntegrationTests/ParsableTests.cs | 6 ++++++ version.props | 2 +- 10 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs create mode 100644 src/StronglyTypedIds/Templates/Int/Int_Parsable.cs create mode 100644 src/StronglyTypedIds/Templates/Long/Long_Parsable.cs create mode 100644 src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs create mode 100644 src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs create mode 100644 src/StronglyTypedIds/Templates/String/String_Parsable.cs create mode 100644 test/StronglyTypedIds.IntegrationTests/ParsableTests.cs diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs index d0900fc4f..3eaab840b 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs @@ -33,5 +33,12 @@ public enum StronglyTypedIdImplementations /// Implement the interface /// IComparable = 4, + + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, } -} \ No newline at end of file +} diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index 5ed4a79d4..0a59dc895 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -73,6 +73,7 @@ static string CreateId( var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable); var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable); + var useParsable = implementations.IsSet(StronglyTypedIdImplementations.IParsable); var parentsCount = 0; @@ -130,7 +131,7 @@ static string CreateId( sb.Append(resources.BaseId); - ReplaceInterfaces(sb, useIEquatable, useIComparable); + ReplaceInterfaces(sb, useIEquatable, useIComparable, useParsable); // IEquatable is already implemented whether or not the interface is implemented @@ -185,7 +186,7 @@ static string CreateId( return sb.ToString(); } - private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool useIComparable) + private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool useIComparable, bool useParsable) { var interfaces = new List(); @@ -199,6 +200,11 @@ private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool interfaces.Add("System.IEquatable"); } + if (useParsable) + { + interfaces.Add("System.IParsable"); + } + if (interfaces.Count > 0) { sb.Replace("INTERFACES", string.Join(", ", interfaces)); diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs b/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/src/StronglyTypedIds/Templates/String/String_Parsable.cs b/src/StronglyTypedIds/Templates/String/String_Parsable.cs new file mode 100644 index 000000000..d205c674e --- /dev/null +++ b/src/StronglyTypedIds/Templates/String/String_Parsable.cs @@ -0,0 +1,10 @@ + + public static TESTID Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + { + throw new NotImplementedException(); + } diff --git a/test/StronglyTypedIds.IntegrationTests/ParsableTests.cs b/test/StronglyTypedIds.IntegrationTests/ParsableTests.cs new file mode 100644 index 000000000..403fccc2f --- /dev/null +++ b/test/StronglyTypedIds.IntegrationTests/ParsableTests.cs @@ -0,0 +1,6 @@ +namespace StronglyTypedIds.IntegrationTests; + +public class ParsableTests +{ + +} \ No newline at end of file diff --git a/version.props b/version.props index abf34b4ae..716d80ec4 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.1 + 1.0.2 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From caad21dfce71efc34023d96c84919b4c8811e25a Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 16:15:04 +0300 Subject: [PATCH 17/37] Parsable Tests --- .../StronglyTypedIdImplementations.cs | 5 +- .../SourceGenerationHelper.cs | 7 + ...onglyTypedIdAttribute.Core3_1.received.txt | 62 ++++++ ...glyTypedIdAttribute.DotNet6_0.received.txt | 62 ++++++ ...glyTypedIdAttribute.DotNet7_0.received.txt | 62 ++++++ ...urce=StronglyTypedIdAttribute.verified.txt | 63 +----- ...TypedIdImplementations.Net4_8.received.txt | 60 ++++++ ...tronglyTypedIdImplementations.verified.txt | 52 +---- ...IdCorrectly_type=Guid.Core3_1.received.txt | 157 ++++++++++++++ ...IdCorrectly_type=Guid.Core3_1.verified.txt | 157 ++++++++++++++ ...Correctly_type=Guid.DotNet6_0.received.txt | 157 ++++++++++++++ ...Correctly_type=Guid.DotNet6_0.verified.txt | 157 ++++++++++++++ ...Correctly_type=Guid.DotNet7_0.received.txt | 157 ++++++++++++++ ...Correctly_type=Guid.DotNet7_0.verified.txt | 157 ++++++++++++++ ...lIdCorrectly_type=Guid.Net4_8.received.txt | 157 ++++++++++++++ ...lIdCorrectly_type=Guid.Net4_8.verified.txt | 157 ++++++++++++++ ...atesFullIdCorrectly_type=Guid.verified.txt | 158 +-------------- ...lIdCorrectly_type=Int.Core3_1.received.txt | 157 ++++++++++++++ ...lIdCorrectly_type=Int.Core3_1.verified.txt | 157 ++++++++++++++ ...dCorrectly_type=Int.DotNet6_0.received.txt | 157 ++++++++++++++ ...dCorrectly_type=Int.DotNet6_0.verified.txt | 157 ++++++++++++++ ...dCorrectly_type=Int.DotNet7_0.received.txt | 157 ++++++++++++++ ...dCorrectly_type=Int.DotNet7_0.verified.txt | 157 ++++++++++++++ ...llIdCorrectly_type=Int.Net4_8.received.txt | 157 ++++++++++++++ ...llIdCorrectly_type=Int.Net4_8.verified.txt | 157 ++++++++++++++ ...ratesFullIdCorrectly_type=Int.verified.txt | 158 +-------------- ...IdCorrectly_type=Long.Core3_1.received.txt | 160 +++++++++++++++ ...IdCorrectly_type=Long.Core3_1.verified.txt | 160 +++++++++++++++ ...Correctly_type=Long.DotNet6_0.received.txt | 160 +++++++++++++++ ...Correctly_type=Long.DotNet6_0.verified.txt | 160 +++++++++++++++ ...Correctly_type=Long.DotNet7_0.received.txt | 160 +++++++++++++++ ...Correctly_type=Long.DotNet7_0.verified.txt | 160 +++++++++++++++ ...lIdCorrectly_type=Long.Net4_8.received.txt | 160 +++++++++++++++ ...lIdCorrectly_type=Long.Net4_8.verified.txt | 160 +++++++++++++++ ...atesFullIdCorrectly_type=Long.verified.txt | 161 +-------------- ...type=MassTransitNewId.Core3_1.received.txt | 165 +++++++++++++++ ...type=MassTransitNewId.Core3_1.verified.txt | 165 +++++++++++++++ ...pe=MassTransitNewId.DotNet6_0.received.txt | 165 +++++++++++++++ ...pe=MassTransitNewId.DotNet6_0.verified.txt | 165 +++++++++++++++ ...pe=MassTransitNewId.DotNet7_0.received.txt | 165 +++++++++++++++ ...pe=MassTransitNewId.DotNet7_0.verified.txt | 165 +++++++++++++++ ..._type=MassTransitNewId.Net4_8.received.txt | 165 +++++++++++++++ ..._type=MassTransitNewId.Net4_8.verified.txt | 165 +++++++++++++++ ...rrectly_type=MassTransitNewId.verified.txt | 166 +-------------- ...y_type=NullableString.Core3_1.received.txt | 190 +++++++++++++++++ ...y_type=NullableString.Core3_1.verified.txt | 190 +++++++++++++++++ ...type=NullableString.DotNet6_0.received.txt | 190 +++++++++++++++++ ...type=NullableString.DotNet6_0.verified.txt | 190 +++++++++++++++++ ...type=NullableString.DotNet7_0.received.txt | 190 +++++++++++++++++ ...type=NullableString.DotNet7_0.verified.txt | 190 +++++++++++++++++ ...ly_type=NullableString.Net4_8.received.txt | 190 +++++++++++++++++ ...ly_type=NullableString.Net4_8.verified.txt | 190 +++++++++++++++++ ...Correctly_type=NullableString.verified.txt | 191 +----------------- ...Correctly_type=String.Core3_1.received.txt | 176 ++++++++++++++++ ...Correctly_type=String.Core3_1.verified.txt | 176 ++++++++++++++++ ...rrectly_type=String.DotNet6_0.received.txt | 176 ++++++++++++++++ ...rrectly_type=String.DotNet6_0.verified.txt | 176 ++++++++++++++++ ...rrectly_type=String.DotNet7_0.received.txt | 176 ++++++++++++++++ ...rrectly_type=String.DotNet7_0.verified.txt | 176 ++++++++++++++++ ...dCorrectly_type=String.Net4_8.received.txt | 176 ++++++++++++++++ ...dCorrectly_type=String.Net4_8.verified.txt | 176 ++++++++++++++++ ...esFullIdCorrectly_type=String.verified.txt | 177 +--------------- ...perTypeHandler_i=None.Core3_1.received.txt | 54 +++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++++ ...id_c=DapperTypeHandler_i=None.verified.txt | 55 +---- ...ValueConverter_i=None.Core3_1.received.txt | 47 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 47 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 47 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 47 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 47 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 47 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 47 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 47 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 48 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 57 ++++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 ++++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 57 ++++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 ++++++ ...=Guid_c=NewtonsoftJson_i=None.verified.txt | 58 +----- ..._c=None_i=IComparable.Core3_1.received.txt | 37 ++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 37 ++++ ...=None_i=IComparable.DotNet6_0.received.txt | 37 ++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 37 ++++ ...=None_i=IComparable.DotNet7_0.received.txt | 37 ++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 37 ++++ ...d_c=None_i=IComparable.Net4_8.received.txt | 37 ++++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 ++++ ...ype=Guid_c=None_i=IComparable.verified.txt | 38 +--- ...d_c=None_i=IEquatable.Core3_1.received.txt | 36 ++++ ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 36 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 36 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 ++++ ...id_c=None_i=IEquatable.Net4_8.received.txt | 36 ++++ ...id_c=None_i=IEquatable.Net4_8.verified.txt | 36 ++++ ...type=Guid_c=None_i=IEquatable.verified.txt | 37 +--- ...id_c=None_i=IParsable.Core3_1.received.txt | 36 ++++ ...id_c=None_i=IParsable.Core3_1.verified.txt | 36 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 36 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 36 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 ++++ ...uid_c=None_i=IParsable.Net4_8.received.txt | 36 ++++ ...uid_c=None_i=IParsable.Net4_8.verified.txt | 36 ++++ ..._type=Guid_c=None_i=IParsable.verified.txt | 1 + ...pe=Guid_c=None_i=None.Core3_1.received.txt | 36 ++++ ...pe=Guid_c=None_i=None.Core3_1.verified.txt | 36 ++++ ...=Guid_c=None_i=None.DotNet6_0.received.txt | 36 ++++ ...=Guid_c=None_i=None.DotNet6_0.verified.txt | 36 ++++ ...=Guid_c=None_i=None.DotNet7_0.received.txt | 36 ++++ ...=Guid_c=None_i=None.DotNet7_0.verified.txt | 36 ++++ ...ype=Guid_c=None_i=None.Net4_8.received.txt | 36 ++++ ...ype=Guid_c=None_i=None.Net4_8.verified.txt | 36 ++++ ...ectly_type=Guid_c=None_i=None.verified.txt | 37 +--- ...erSchemaFilter_i=None.Core3_1.received.txt | 50 +++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 +++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 50 +++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 +++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 50 +++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 +++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 50 +++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 +++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 51 +---- ...SystemTextJson_i=None.Core3_1.received.txt | 50 +++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 50 +++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 50 +++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 +++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 50 +++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 +++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 50 +++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 +++++ ...=Guid_c=SystemTextJson_i=None.verified.txt | 51 +---- ...=TypeConverter_i=None.Core3_1.received.txt | 78 +++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 78 +++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 78 +++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 78 +++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 78 +++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 78 +++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 78 +++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 78 +++++++ ...e=Guid_c=TypeConverter_i=None.verified.txt | 79 +------- ...perTypeHandler_i=None.Core3_1.received.txt | 54 +++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++++ ...nt_c=DapperTypeHandler_i=None.verified.txt | 55 +---- ...ValueConverter_i=None.Core3_1.received.txt | 46 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 46 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 46 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 46 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 46 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 46 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 46 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 46 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 47 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 56 +++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 +++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 56 +++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 +++++ ...e=Int_c=NewtonsoftJson_i=None.verified.txt | 57 +----- ..._c=None_i=IComparable.Core3_1.received.txt | 36 ++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 36 ++++ ...=None_i=IComparable.DotNet6_0.received.txt | 36 ++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 36 ++++ ...=None_i=IComparable.DotNet7_0.received.txt | 36 ++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 36 ++++ ...t_c=None_i=IComparable.Net4_8.received.txt | 36 ++++ ...t_c=None_i=IComparable.Net4_8.verified.txt | 36 ++++ ...type=Int_c=None_i=IComparable.verified.txt | 37 +--- ...t_c=None_i=IEquatable.Core3_1.received.txt | 35 ++++ ...t_c=None_i=IEquatable.Core3_1.verified.txt | 35 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 35 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 35 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 ++++ ...nt_c=None_i=IEquatable.Net4_8.received.txt | 35 ++++ ...nt_c=None_i=IEquatable.Net4_8.verified.txt | 35 ++++ ..._type=Int_c=None_i=IEquatable.verified.txt | 36 +--- ...nt_c=None_i=IParsable.Core3_1.received.txt | 35 ++++ ...nt_c=None_i=IParsable.Core3_1.verified.txt | 35 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 35 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 35 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 ++++ ...Int_c=None_i=IParsable.Net4_8.received.txt | 35 ++++ ...Int_c=None_i=IParsable.Net4_8.verified.txt | 35 ++++ ...y_type=Int_c=None_i=IParsable.verified.txt | 1 + ...ype=Int_c=None_i=None.Core3_1.received.txt | 35 ++++ ...ype=Int_c=None_i=None.Core3_1.verified.txt | 35 ++++ ...e=Int_c=None_i=None.DotNet6_0.received.txt | 35 ++++ ...e=Int_c=None_i=None.DotNet6_0.verified.txt | 35 ++++ ...e=Int_c=None_i=None.DotNet7_0.received.txt | 35 ++++ ...e=Int_c=None_i=None.DotNet7_0.verified.txt | 35 ++++ ...type=Int_c=None_i=None.Net4_8.received.txt | 35 ++++ ...type=Int_c=None_i=None.Net4_8.verified.txt | 35 ++++ ...rectly_type=Int_c=None_i=None.verified.txt | 36 +--- ...erSchemaFilter_i=None.Core3_1.received.txt | 49 +++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 +++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 49 +++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 +++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 49 +++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 +++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 49 +++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 +++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 50 +---- ...SystemTextJson_i=None.Core3_1.received.txt | 49 +++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 49 +++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 49 +++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 +++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 49 +++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 +++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 49 +++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 +++++ ...e=Int_c=SystemTextJson_i=None.verified.txt | 50 +---- ...=TypeConverter_i=None.Core3_1.received.txt | 77 +++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 77 +++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 77 +++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 77 +++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 77 +++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 77 +++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 77 +++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 77 +++++++ ...pe=Int_c=TypeConverter_i=None.verified.txt | 78 +------ ...perTypeHandler_i=None.Core3_1.received.txt | 55 +++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 55 +++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 55 +++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 55 +++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 55 +++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 55 +++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 55 +++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 55 +++++ ...ng_c=DapperTypeHandler_i=None.verified.txt | 56 +---- ...ValueConverter_i=None.Core3_1.received.txt | 46 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 46 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 46 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 46 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 46 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 46 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 46 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 46 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 47 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 56 +++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 56 +++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 +++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 56 +++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 +++++ ...=Long_c=NewtonsoftJson_i=None.verified.txt | 57 +----- ..._c=None_i=IComparable.Core3_1.received.txt | 36 ++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 36 ++++ ...=None_i=IComparable.DotNet6_0.received.txt | 36 ++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 36 ++++ ...=None_i=IComparable.DotNet7_0.received.txt | 36 ++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 36 ++++ ...g_c=None_i=IComparable.Net4_8.received.txt | 36 ++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 36 ++++ ...ype=Long_c=None_i=IComparable.verified.txt | 37 +--- ...g_c=None_i=IEquatable.Core3_1.received.txt | 35 ++++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 35 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 35 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 35 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 ++++ ...ng_c=None_i=IEquatable.Net4_8.received.txt | 35 ++++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 35 ++++ ...type=Long_c=None_i=IEquatable.verified.txt | 36 +--- ...ng_c=None_i=IParsable.Core3_1.received.txt | 35 ++++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 35 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 35 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 35 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 ++++ ...ong_c=None_i=IParsable.Net4_8.received.txt | 35 ++++ ...ong_c=None_i=IParsable.Net4_8.verified.txt | 35 ++++ ..._type=Long_c=None_i=IParsable.verified.txt | 1 + ...pe=Long_c=None_i=None.Core3_1.received.txt | 35 ++++ ...pe=Long_c=None_i=None.Core3_1.verified.txt | 35 ++++ ...=Long_c=None_i=None.DotNet6_0.received.txt | 35 ++++ ...=Long_c=None_i=None.DotNet6_0.verified.txt | 35 ++++ ...=Long_c=None_i=None.DotNet7_0.received.txt | 35 ++++ ...=Long_c=None_i=None.DotNet7_0.verified.txt | 35 ++++ ...ype=Long_c=None_i=None.Net4_8.received.txt | 35 ++++ ...ype=Long_c=None_i=None.Net4_8.verified.txt | 35 ++++ ...ectly_type=Long_c=None_i=None.verified.txt | 36 +--- ...erSchemaFilter_i=None.Core3_1.received.txt | 49 +++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 +++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 49 +++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 +++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 49 +++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 +++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 49 +++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 +++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 50 +---- ...SystemTextJson_i=None.Core3_1.received.txt | 49 +++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 49 +++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 49 +++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 +++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 49 +++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 +++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 49 +++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 +++++ ...=Long_c=SystemTextJson_i=None.verified.txt | 50 +---- ...=TypeConverter_i=None.Core3_1.received.txt | 79 ++++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 79 ++++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 79 ++++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 79 ++++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 79 ++++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 79 ++++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 79 ++++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 79 ++++++++ ...e=Long_c=TypeConverter_i=None.verified.txt | 80 +------- ...perTypeHandler_i=None.Core3_1.received.txt | 54 +++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 +++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 54 +++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++++ ...Id_c=DapperTypeHandler_i=None.verified.txt | 55 +---- ...ValueConverter_i=None.Core3_1.received.txt | 47 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 47 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 47 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 47 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 47 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 47 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 47 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 47 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 48 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 57 ++++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 57 ++++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 ++++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 57 ++++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 ++++++ ...NewId_c=NewtonsoftJson_i=None.verified.txt | 58 +----- ..._c=None_i=IComparable.Core3_1.received.txt | 37 ++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 37 ++++ ...=None_i=IComparable.DotNet6_0.received.txt | 37 ++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 37 ++++ ...=None_i=IComparable.DotNet7_0.received.txt | 37 ++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 37 ++++ ...d_c=None_i=IComparable.Net4_8.received.txt | 37 ++++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 ++++ ...sitNewId_c=None_i=IComparable.verified.txt | 38 +--- ...d_c=None_i=IEquatable.Core3_1.received.txt | 36 ++++ ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 36 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 36 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 ++++ ...Id_c=None_i=IEquatable.Net4_8.received.txt | 36 ++++ ...Id_c=None_i=IEquatable.Net4_8.verified.txt | 36 ++++ ...nsitNewId_c=None_i=IEquatable.verified.txt | 37 +--- ...Id_c=None_i=IParsable.Core3_1.received.txt | 36 ++++ ...Id_c=None_i=IParsable.Core3_1.verified.txt | 36 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 36 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 36 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 ++++ ...wId_c=None_i=IParsable.Net4_8.received.txt | 36 ++++ ...wId_c=None_i=IParsable.Net4_8.verified.txt | 36 ++++ ...ansitNewId_c=None_i=IParsable.verified.txt | 1 + ...itNewId_c=None_i=None.Core3_1.received.txt | 36 ++++ ...itNewId_c=None_i=None.Core3_1.verified.txt | 36 ++++ ...NewId_c=None_i=None.DotNet6_0.received.txt | 36 ++++ ...NewId_c=None_i=None.DotNet6_0.verified.txt | 36 ++++ ...NewId_c=None_i=None.DotNet7_0.received.txt | 36 ++++ ...NewId_c=None_i=None.DotNet7_0.verified.txt | 36 ++++ ...sitNewId_c=None_i=None.Net4_8.received.txt | 36 ++++ ...sitNewId_c=None_i=None.Net4_8.verified.txt | 36 ++++ ...assTransitNewId_c=None_i=None.verified.txt | 37 +--- ...erSchemaFilter_i=None.Core3_1.received.txt | 50 +++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 +++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 50 +++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 +++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 50 +++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 +++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 50 +++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 +++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 51 +---- ...SystemTextJson_i=None.Core3_1.received.txt | 50 +++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 50 +++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 50 +++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 +++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 50 +++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 +++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 50 +++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 +++++ ...NewId_c=SystemTextJson_i=None.verified.txt | 51 +---- ...=TypeConverter_i=None.Core3_1.received.txt | 86 ++++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 86 ++++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 86 ++++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 86 ++++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 86 ++++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 86 ++++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 86 ++++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 86 ++++++++ ...tNewId_c=TypeConverter_i=None.verified.txt | 87 +------- ...perTypeHandler_i=None.Core3_1.received.txt | 63 ++++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 63 ++++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 63 ++++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 63 ++++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 63 ++++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 63 ++++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 63 ++++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 63 ++++++ ...ng_c=DapperTypeHandler_i=None.verified.txt | 64 +----- ...ValueConverter_i=None.Core3_1.received.txt | 55 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 55 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 55 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 55 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 55 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 55 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 55 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 55 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 56 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 71 +++++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 +++++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 71 +++++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 +++++++ ...tring_c=NewtonsoftJson_i=None.verified.txt | 72 +------ ..._c=None_i=IComparable.Core3_1.received.txt | 54 +++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 54 +++++ ...=None_i=IComparable.DotNet6_0.received.txt | 54 +++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 54 +++++ ...=None_i=IComparable.DotNet7_0.received.txt | 54 +++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 54 +++++ ...g_c=None_i=IComparable.Net4_8.received.txt | 54 +++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 +++++ ...leString_c=None_i=IComparable.verified.txt | 55 +---- ...g_c=None_i=IEquatable.Core3_1.received.txt | 44 ++++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 44 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 44 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 ++++ ...ng_c=None_i=IEquatable.Net4_8.received.txt | 44 ++++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 ++++ ...bleString_c=None_i=IEquatable.verified.txt | 45 +---- ...ng_c=None_i=IParsable.Core3_1.received.txt | 44 ++++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 44 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 44 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 ++++ ...ing_c=None_i=IParsable.Net4_8.received.txt | 44 ++++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 ++++ ...ableString_c=None_i=IParsable.verified.txt | 1 + ...eString_c=None_i=None.Core3_1.received.txt | 44 ++++ ...eString_c=None_i=None.Core3_1.verified.txt | 44 ++++ ...tring_c=None_i=None.DotNet6_0.received.txt | 44 ++++ ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 ++++ ...tring_c=None_i=None.DotNet7_0.received.txt | 44 ++++ ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 ++++ ...leString_c=None_i=None.Net4_8.received.txt | 44 ++++ ...leString_c=None_i=None.Net4_8.verified.txt | 44 ++++ ...=NullableString_c=None_i=None.verified.txt | 45 +---- ...erSchemaFilter_i=None.Core3_1.received.txt | 59 ++++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 ++++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 59 ++++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 ++++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 60 +----- ...SystemTextJson_i=None.Core3_1.received.txt | 65 ++++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 65 ++++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 65 ++++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 65 ++++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 65 ++++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 65 ++++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 65 ++++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 65 ++++++ ...tring_c=SystemTextJson_i=None.verified.txt | 66 +----- ...=TypeConverter_i=None.Core3_1.received.txt | 87 ++++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 87 ++++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 87 ++++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 87 ++++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 87 ++++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 87 ++++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 87 ++++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 87 ++++++++ ...String_c=TypeConverter_i=None.verified.txt | 88 +------- ...perTypeHandler_i=None.Core3_1.received.txt | 61 ++++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 61 ++++++ ...rTypeHandler_i=None.DotNet6_0.received.txt | 61 ++++++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 61 ++++++ ...rTypeHandler_i=None.DotNet7_0.received.txt | 61 ++++++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 61 ++++++ ...pperTypeHandler_i=None.Net4_8.received.txt | 61 ++++++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 61 ++++++ ...ng_c=DapperTypeHandler_i=None.verified.txt | 62 +----- ...ValueConverter_i=None.Core3_1.received.txt | 55 +++++ ...ValueConverter_i=None.Core3_1.verified.txt | 55 +++++ ...lueConverter_i=None.DotNet6_0.received.txt | 55 +++++ ...lueConverter_i=None.DotNet6_0.verified.txt | 55 +++++ ...lueConverter_i=None.DotNet7_0.received.txt | 55 +++++ ...lueConverter_i=None.DotNet7_0.verified.txt | 55 +++++ ...eValueConverter_i=None.Net4_8.received.txt | 55 +++++ ...eValueConverter_i=None.Net4_8.verified.txt | 55 +++++ ...c=EfCoreValueConverter_i=None.verified.txt | 56 +---- ...NewtonsoftJson_i=None.Core3_1.received.txt | 71 +++++++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet6_0.received.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet7_0.received.txt | 71 +++++++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 +++++++ ...=NewtonsoftJson_i=None.Net4_8.received.txt | 71 +++++++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 +++++++ ...tring_c=NewtonsoftJson_i=None.verified.txt | 72 +------ ..._c=None_i=IComparable.Core3_1.received.txt | 54 +++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 54 +++++ ...=None_i=IComparable.DotNet6_0.received.txt | 54 +++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 54 +++++ ...=None_i=IComparable.DotNet7_0.received.txt | 54 +++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 54 +++++ ...g_c=None_i=IComparable.Net4_8.received.txt | 54 +++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 +++++ ...e=String_c=None_i=IComparable.verified.txt | 55 +---- ...g_c=None_i=IEquatable.Core3_1.received.txt | 44 ++++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 ++++ ...c=None_i=IEquatable.DotNet6_0.received.txt | 44 ++++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 ++++ ...c=None_i=IEquatable.DotNet7_0.received.txt | 44 ++++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 ++++ ...ng_c=None_i=IEquatable.Net4_8.received.txt | 44 ++++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 ++++ ...pe=String_c=None_i=IEquatable.verified.txt | 45 +---- ...ng_c=None_i=IParsable.Core3_1.received.txt | 44 ++++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 ++++ ..._c=None_i=IParsable.DotNet6_0.received.txt | 44 ++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 ++++ ..._c=None_i=IParsable.DotNet7_0.received.txt | 44 ++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 ++++ ...ing_c=None_i=IParsable.Net4_8.received.txt | 44 ++++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 ++++ ...ype=String_c=None_i=IParsable.verified.txt | 1 + ...=String_c=None_i=None.Core3_1.received.txt | 44 ++++ ...=String_c=None_i=None.Core3_1.verified.txt | 44 ++++ ...tring_c=None_i=None.DotNet6_0.received.txt | 44 ++++ ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 ++++ ...tring_c=None_i=None.DotNet7_0.received.txt | 44 ++++ ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 ++++ ...e=String_c=None_i=None.Net4_8.received.txt | 44 ++++ ...e=String_c=None_i=None.Net4_8.verified.txt | 44 ++++ ...tly_type=String_c=None_i=None.verified.txt | 45 +---- ...erSchemaFilter_i=None.Core3_1.received.txt | 59 ++++++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet6_0.received.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet7_0.received.txt | 59 ++++++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 ++++++ ...gerSchemaFilter_i=None.Net4_8.received.txt | 59 ++++++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 ++++++ ..._c=SwaggerSchemaFilter_i=None.verified.txt | 60 +----- ...SystemTextJson_i=None.Core3_1.received.txt | 58 ++++++ ...SystemTextJson_i=None.Core3_1.verified.txt | 58 ++++++ ...stemTextJson_i=None.DotNet6_0.received.txt | 58 ++++++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 58 ++++++ ...stemTextJson_i=None.DotNet7_0.received.txt | 58 ++++++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 58 ++++++ ...=SystemTextJson_i=None.Net4_8.received.txt | 58 ++++++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 58 ++++++ ...tring_c=SystemTextJson_i=None.verified.txt | 59 +----- ...=TypeConverter_i=None.Core3_1.received.txt | 82 ++++++++ ...=TypeConverter_i=None.Core3_1.verified.txt | 82 ++++++++ ...ypeConverter_i=None.DotNet6_0.received.txt | 82 ++++++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 82 ++++++++ ...ypeConverter_i=None.DotNet7_0.received.txt | 82 ++++++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 82 ++++++++ ...c=TypeConverter_i=None.Net4_8.received.txt | 82 ++++++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 82 ++++++++ ...String_c=TypeConverter_i=None.verified.txt | 83 +------- ...ly_nestedClassCount=0.Core3_1.received.txt | 56 +++++ ...ly_nestedClassCount=0.Core3_1.verified.txt | 56 +++++ ..._nestedClassCount=0.DotNet6_0.received.txt | 56 +++++ ..._nestedClassCount=0.DotNet6_0.verified.txt | 56 +++++ ..._nestedClassCount=0.DotNet7_0.received.txt | 56 +++++ ..._nestedClassCount=0.DotNet7_0.verified.txt | 56 +++++ ...tly_nestedClassCount=0.Net4_8.received.txt | 56 +++++ ...tly_nestedClassCount=0.Net4_8.verified.txt | 56 +++++ ...sCorrectly_nestedClassCount=0.verified.txt | 57 +----- ...ly_nestedClassCount=1.Core3_1.received.txt | 59 ++++++ ...ly_nestedClassCount=1.Core3_1.verified.txt | 59 ++++++ ..._nestedClassCount=1.DotNet6_0.received.txt | 59 ++++++ ..._nestedClassCount=1.DotNet6_0.verified.txt | 59 ++++++ ..._nestedClassCount=1.DotNet7_0.received.txt | 59 ++++++ ..._nestedClassCount=1.DotNet7_0.verified.txt | 59 ++++++ ...tly_nestedClassCount=1.Net4_8.received.txt | 59 ++++++ ...tly_nestedClassCount=1.Net4_8.verified.txt | 59 ++++++ ...sCorrectly_nestedClassCount=1.verified.txt | 60 +----- ...ly_nestedClassCount=2.Core3_1.received.txt | 62 ++++++ ...ly_nestedClassCount=2.Core3_1.verified.txt | 62 ++++++ ..._nestedClassCount=2.DotNet6_0.received.txt | 62 ++++++ ..._nestedClassCount=2.DotNet6_0.verified.txt | 62 ++++++ ..._nestedClassCount=2.DotNet7_0.received.txt | 62 ++++++ ..._nestedClassCount=2.DotNet7_0.verified.txt | 62 ++++++ ...tly_nestedClassCount=2.Net4_8.received.txt | 62 ++++++ ...tly_nestedClassCount=2.Net4_8.verified.txt | 62 ++++++ ...sCorrectly_nestedClassCount=2.verified.txt | 63 +----- 629 files changed, 34383 insertions(+), 4142 deletions(-) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs index 3eaab840b..bb0a333a8 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs @@ -8,7 +8,7 @@ namespace StronglyTypedIds [Flags] public enum StronglyTypedIdImplementations { - // Used with HasFlag, so needs to be 1, 2, 4 etc + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc /// /// Don't implement any additional members for the strongly typed ID @@ -34,11 +34,12 @@ public enum StronglyTypedIdImplementations /// IComparable = 4, - + #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// IParsable = 8, + #endif } } diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index 0a59dc895..aa392441a 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -73,7 +73,10 @@ static string CreateId( var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable); var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable); + + #if NET7_0_OR_GREATER var useParsable = implementations.IsSet(StronglyTypedIdImplementations.IParsable); + #endif var parentsCount = 0; @@ -131,7 +134,11 @@ static string CreateId( sb.Append(resources.BaseId); + #if NET7_0_OR_GREATER ReplaceInterfaces(sb, useIEquatable, useIComparable, useParsable); + #else + ReplaceInterfaces(sb, useIEquatable, useIComparable, false); + #endif // IEquatable is already implemented whether or not the interface is implemented diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt index 58a2c4794..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt @@ -1,62 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt new file mode 100644 index 000000000..fec04c8e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt index 76835ffec..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt @@ -1,51 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif \ No newline at end of file + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 7ee4bd7d4..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -1,157 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index d65d51495..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -1,157 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt new file mode 100644 index 000000000..3fa5fad11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt new file mode 100644 index 000000000..3fa5fad11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt new file mode 100644 index 000000000..3fa5fad11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt new file mode 100644 index 000000000..3fa5fad11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 09643c593..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -1,160 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index caa78ba07..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -1,165 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index b45ca58f8..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -1,190 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt new file mode 100644 index 000000000..8612d81b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt new file mode 100644 index 000000000..8612d81b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt new file mode 100644 index 000000000..8612d81b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt new file mode 100644 index 000000000..8612d81b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 8612d81b5..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -1,176 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt index bb6b344ab..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt @@ -1,54 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt index 508208c37..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt @@ -1,47 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt index db59f66c1..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt @@ -1,57 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt index bef90429e..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt @@ -1,37 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt index a13e9bec6..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt index fad5ea0b5..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt index f72224715..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,50 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt index d6d801a99..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt @@ -1,50 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt index 295e92baf..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt @@ -1,78 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt index f8d24bbf5..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt @@ -1,54 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt index d3e50467b..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt @@ -1,46 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt index b4d9738e7..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt @@ -1,56 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt index d76d3afd2..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt index 5d23b64a1..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt @@ -1,35 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt index 45272d34a..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt @@ -1,35 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt index 297090ba1..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,49 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt index 7c016c3be..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt @@ -1,49 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt index 39f1e9331..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt @@ -1,77 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..35fd482b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt index 35fd482b5..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt @@ -1,55 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt index cb5754863..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt @@ -1,46 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt index 7052a3b27..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt @@ -1,56 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt index c38fa63f6..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt index 13b9b1ac7..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt @@ -1,35 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt index af1658c35..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt @@ -1,35 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt index 72b024dca..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,49 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt index 17a45333f..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt @@ -1,49 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt index e22d0478c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt @@ -1,79 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt index 23efe4b09..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt @@ -1,54 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt index 9114f2d54..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt @@ -1,47 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt index 181d85e44..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt @@ -1,57 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt index 3a19fc65e..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt @@ -1,37 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt index b4c2d5867..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt index 7e4892f41..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt index 699828755..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,50 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt index 3de0600ab..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt @@ -1,50 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt index 757eb4ebb..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt @@ -1,86 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt index c96f1e168..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt @@ -1,63 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt index e1a174104..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt @@ -1,55 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt index 9660c1fc0..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt @@ -1,71 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt index d779d1af4..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt @@ -1,54 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt index bb2e2c7d2..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt @@ -1,44 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt index fe1e43665..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt @@ -1,44 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt index c85338e9a..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,59 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt index c049fb7f5..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt @@ -1,65 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt index 50b3c0585..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt @@ -1,87 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt index 749dd1dbd..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt @@ -1,61 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt index 05700f78d..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt @@ -1,55 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt index d7596bf2b..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt @@ -1,71 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt index 4fae5139a..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt @@ -1,54 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt index 050bcc20b..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt @@ -1,44 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt index 0987c7d64..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt @@ -1,44 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt index 6e4590319..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1,59 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt index 1396ccae3..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt @@ -1,58 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt index d35ac20a3..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt @@ -1,82 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt index ff61cdde7..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt @@ -1,56 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt index dacf3158c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt @@ -1,59 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt index b71458e7e..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt @@ -1,62 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} + \ No newline at end of file From bc67c8526c83d114c3c6acd4833353e8d65169c3 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 16:15:38 +0300 Subject: [PATCH 18/37] parsable tests --- ...ce=StronglyTypedIdBackingType.verified.txt | 37 +- ...urce=StronglyTypedIdConverter.verified.txt | 71 +-- ...onglyTypedIdDefaultsAttribute.verified.txt | 61 +-- ...ateDefaultIdInGlobalNamespace.verified.txt | 325 +------------ ...nerateIdInFileScopedNamespace.verified.txt | 328 +------------ ...ests.CanGenerateIdInNamespace.verified.txt | 328 +------------ ...ewtonsoftJson, SystemTextJson.verified.txt | 300 +----------- ...Guid_converter=NewtonsoftJson.verified.txt | 286 +----------- ...Guid_converter=SystemTextJson.verified.txt | 279 +---------- ...=Guid_converter=TypeConverter.verified.txt | 307 +------------ ...ckingType=Guid_converter=null.verified.txt | 328 +------------ ...ewtonsoftJson, SystemTextJson.verified.txt | 300 +----------- ...Guid_converter=NewtonsoftJson.verified.txt | 286 +----------- ...Guid_converter=SystemTextJson.verified.txt | 279 +---------- ...=Guid_converter=TypeConverter.verified.txt | 307 +------------ ...ckingType=Guid_converter=null.verified.txt | 328 +------------ ...nerateMultipleIdsWithSameName.verified.txt | 432 +----------------- ...eNestedIdInFileScopeNamespace.verified.txt | 331 +------------- ...yNestedIdInFileScopeNamespace.verified.txt | 337 +------------- ...eDefaultsUsingGlobalAttribute.verified.txt | 261 +---------- 20 files changed, 20 insertions(+), 5491 deletions(-) diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt index 4ea1be319..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt @@ -1,36 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif \ No newline at end of file + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt index f9fffe68a..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt @@ -1,70 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif \ No newline at end of file + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt index 3df9e2e31..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt @@ -1,60 +1 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 9800a32ec..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -1,324 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index cf0b59cc6..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -1,327 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index cf0b59cc6..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -1,327 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index ae10a54b7..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -1,299 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index fbb9ed982..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -1,285 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 7de59eb4c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -1,278 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 5a9b9674e..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -1,306 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index ea0fbaa4c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -1,327 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index ae10a54b7..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -1,299 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index fbb9ed982..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -1,285 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 7de59eb4c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -1,278 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 5a9b9674e..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -1,306 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index ea0fbaa4c..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -1,327 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index bbd3238f8..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -1,431 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V1 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} - -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V2 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 478076d59..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -1,330 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index 78053d0fe..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -1,336 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass where T: new() - { - partial record InnerClass - { - partial struct InnerStruct - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } - } - } -} + \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index cdba9ab50..5f282702b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -1,260 +1 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - } -} -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyId(int value) - { - Value = value; - } - - public static readonly MyId Empty = new MyId(0); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - } + \ No newline at end of file From 97855060e49bb9b694b23ec4d0b1bb0f9698d1e5 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 17:27:06 +0300 Subject: [PATCH 19/37] parsing tests --- ...nglyTypedIdAttribute.Core3_1.verified.txt} | 0 ...lyTypedIdAttribute.DotNet6_0.verified.txt} | 0 ...lyTypedIdAttribute.DotNet7_0.verified.txt} | 0 ...ronglyTypedIdAttribute.Net4_8.verified.txt | 62 +++ ...urce=StronglyTypedIdAttribute.verified.txt | 63 ++- ...glyTypedIdBackingType.Core3_1.verified.txt | 36 ++ ...yTypedIdBackingType.DotNet6_0.verified.txt | 36 ++ ...yTypedIdBackingType.DotNet7_0.verified.txt | 36 ++ ...nglyTypedIdBackingType.Net4_8.verified.txt | 36 ++ ...ce=StronglyTypedIdBackingType.verified.txt | 37 +- ...onglyTypedIdConverter.Core3_1.verified.txt | 70 +++ ...glyTypedIdConverter.DotNet6_0.verified.txt | 70 +++ ...glyTypedIdConverter.DotNet7_0.verified.txt | 70 +++ ...ronglyTypedIdConverter.Net4_8.verified.txt | 70 +++ ...urce=StronglyTypedIdConverter.verified.txt | 71 ++- ...edIdDefaultsAttribute.Core3_1.verified.txt | 60 +++ ...IdDefaultsAttribute.DotNet6_0.verified.txt | 60 +++ ...IdDefaultsAttribute.DotNet7_0.verified.txt | 60 +++ ...pedIdDefaultsAttribute.Net4_8.verified.txt | 60 +++ ...onglyTypedIdDefaultsAttribute.verified.txt | 61 ++- ...pedIdImplementations.Core3_1.verified.txt} | 0 ...edIdImplementations.DotNet6_0.verified.txt | 60 +++ ...edIdImplementations.DotNet7_0.verified.txt | 60 +++ ...TypedIdImplementations.Net4_8.verified.txt | 60 +++ ...tronglyTypedIdImplementations.verified.txt | 61 ++- ...IdCorrectly_type=Guid.Core3_1.received.txt | 157 ------- ...IdCorrectly_type=Guid.Core3_1.verified.txt | 2 +- ...Correctly_type=Guid.DotNet6_0.received.txt | 157 ------- ...Correctly_type=Guid.DotNet6_0.verified.txt | 2 +- ...Correctly_type=Guid.DotNet7_0.received.txt | 157 ------- ...Correctly_type=Guid.DotNet7_0.verified.txt | 2 +- ...lIdCorrectly_type=Guid.Net4_8.received.txt | 157 ------- ...lIdCorrectly_type=Guid.Net4_8.verified.txt | 2 +- ...atesFullIdCorrectly_type=Guid.verified.txt | 158 ++++++- ...lIdCorrectly_type=Int.Core3_1.received.txt | 157 ------- ...lIdCorrectly_type=Int.Core3_1.verified.txt | 2 +- ...dCorrectly_type=Int.DotNet6_0.received.txt | 157 ------- ...dCorrectly_type=Int.DotNet6_0.verified.txt | 2 +- ...dCorrectly_type=Int.DotNet7_0.received.txt | 157 ------- ...dCorrectly_type=Int.DotNet7_0.verified.txt | 2 +- ...llIdCorrectly_type=Int.Net4_8.received.txt | 157 ------- ...llIdCorrectly_type=Int.Net4_8.verified.txt | 2 +- ...ratesFullIdCorrectly_type=Int.verified.txt | 158 ++++++- ...IdCorrectly_type=Long.Core3_1.received.txt | 160 ------- ...IdCorrectly_type=Long.Core3_1.verified.txt | 2 +- ...Correctly_type=Long.DotNet6_0.received.txt | 160 ------- ...Correctly_type=Long.DotNet6_0.verified.txt | 2 +- ...Correctly_type=Long.DotNet7_0.received.txt | 160 ------- ...Correctly_type=Long.DotNet7_0.verified.txt | 2 +- ...lIdCorrectly_type=Long.Net4_8.received.txt | 160 ------- ...lIdCorrectly_type=Long.Net4_8.verified.txt | 2 +- ...atesFullIdCorrectly_type=Long.verified.txt | 161 ++++++- ...type=MassTransitNewId.Core3_1.received.txt | 165 ------- ...type=MassTransitNewId.Core3_1.verified.txt | 2 +- ...pe=MassTransitNewId.DotNet6_0.received.txt | 165 ------- ...pe=MassTransitNewId.DotNet6_0.verified.txt | 2 +- ...pe=MassTransitNewId.DotNet7_0.received.txt | 165 ------- ...pe=MassTransitNewId.DotNet7_0.verified.txt | 2 +- ..._type=MassTransitNewId.Net4_8.received.txt | 165 ------- ..._type=MassTransitNewId.Net4_8.verified.txt | 2 +- ...rrectly_type=MassTransitNewId.verified.txt | 166 ++++++- ...y_type=NullableString.Core3_1.received.txt | 190 -------- ...y_type=NullableString.Core3_1.verified.txt | 2 +- ...type=NullableString.DotNet6_0.received.txt | 190 -------- ...type=NullableString.DotNet6_0.verified.txt | 2 +- ...type=NullableString.DotNet7_0.received.txt | 190 -------- ...type=NullableString.DotNet7_0.verified.txt | 2 +- ...ly_type=NullableString.Net4_8.received.txt | 190 -------- ...ly_type=NullableString.Net4_8.verified.txt | 2 +- ...Correctly_type=NullableString.verified.txt | 191 +++++++- ...Correctly_type=String.Core3_1.received.txt | 176 ------- ...Correctly_type=String.Core3_1.verified.txt | 2 +- ...rrectly_type=String.DotNet6_0.received.txt | 176 ------- ...rrectly_type=String.DotNet6_0.verified.txt | 2 +- ...rrectly_type=String.DotNet7_0.received.txt | 176 ------- ...rrectly_type=String.DotNet7_0.verified.txt | 2 +- ...dCorrectly_type=String.Net4_8.received.txt | 176 ------- ...dCorrectly_type=String.Net4_8.verified.txt | 2 +- ...esFullIdCorrectly_type=String.verified.txt | 177 ++++++- ...perTypeHandler_i=None.Core3_1.received.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 54 --- ...id_c=DapperTypeHandler_i=None.verified.txt | 55 ++- ...ValueConverter_i=None.Core3_1.received.txt | 47 -- ...lueConverter_i=None.DotNet6_0.received.txt | 47 -- ...lueConverter_i=None.DotNet7_0.received.txt | 47 -- ...eValueConverter_i=None.Net4_8.received.txt | 47 -- ...c=EfCoreValueConverter_i=None.verified.txt | 48 +- ...NewtonsoftJson_i=None.Core3_1.received.txt | 57 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 57 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 57 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 57 --- ...=Guid_c=NewtonsoftJson_i=None.verified.txt | 58 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 37 -- ...=None_i=IComparable.DotNet6_0.received.txt | 37 -- ...=None_i=IComparable.DotNet7_0.received.txt | 37 -- ...d_c=None_i=IComparable.Net4_8.received.txt | 37 -- ...ype=Guid_c=None_i=IComparable.verified.txt | 38 +- ...d_c=None_i=IEquatable.Core3_1.received.txt | 36 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 36 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 36 -- ...id_c=None_i=IEquatable.Net4_8.received.txt | 36 -- ...type=Guid_c=None_i=IEquatable.verified.txt | 37 +- ..._type=Guid_c=None_i=IParsable.verified.txt | 37 +- ...pe=Guid_c=None_i=None.Core3_1.received.txt | 36 -- ...=Guid_c=None_i=None.DotNet6_0.received.txt | 36 -- ...=Guid_c=None_i=None.DotNet7_0.received.txt | 36 -- ...ype=Guid_c=None_i=None.Net4_8.received.txt | 36 -- ...ectly_type=Guid_c=None_i=None.verified.txt | 37 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 50 -- ...SchemaFilter_i=None.DotNet6_0.received.txt | 50 -- ...SchemaFilter_i=None.DotNet7_0.received.txt | 50 -- ...gerSchemaFilter_i=None.Net4_8.received.txt | 50 -- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 51 +- ...SystemTextJson_i=None.Core3_1.received.txt | 50 -- ...stemTextJson_i=None.DotNet6_0.received.txt | 50 -- ...stemTextJson_i=None.DotNet7_0.received.txt | 50 -- ...=SystemTextJson_i=None.Net4_8.received.txt | 50 -- ...=Guid_c=SystemTextJson_i=None.verified.txt | 51 +- ...=TypeConverter_i=None.Core3_1.received.txt | 78 ---- ...ypeConverter_i=None.DotNet6_0.received.txt | 78 ---- ...ypeConverter_i=None.DotNet7_0.received.txt | 78 ---- ...c=TypeConverter_i=None.Net4_8.received.txt | 78 ---- ...e=Guid_c=TypeConverter_i=None.verified.txt | 79 +++- ...perTypeHandler_i=None.Core3_1.received.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 54 --- ...nt_c=DapperTypeHandler_i=None.verified.txt | 55 ++- ...ValueConverter_i=None.Core3_1.received.txt | 46 -- ...lueConverter_i=None.DotNet6_0.received.txt | 46 -- ...lueConverter_i=None.DotNet7_0.received.txt | 46 -- ...eValueConverter_i=None.Net4_8.received.txt | 46 -- ...c=EfCoreValueConverter_i=None.verified.txt | 47 +- ...NewtonsoftJson_i=None.Core3_1.received.txt | 56 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 56 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 56 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 56 --- ...e=Int_c=NewtonsoftJson_i=None.verified.txt | 57 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 36 -- ...=None_i=IComparable.DotNet6_0.received.txt | 36 -- ...=None_i=IComparable.DotNet7_0.received.txt | 36 -- ...t_c=None_i=IComparable.Net4_8.received.txt | 36 -- ...type=Int_c=None_i=IComparable.verified.txt | 37 +- ...t_c=None_i=IEquatable.Core3_1.received.txt | 35 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 35 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 35 -- ...nt_c=None_i=IEquatable.Net4_8.received.txt | 35 -- ..._type=Int_c=None_i=IEquatable.verified.txt | 36 +- ...y_type=Int_c=None_i=IParsable.verified.txt | 36 +- ...ype=Int_c=None_i=None.Core3_1.received.txt | 35 -- ...e=Int_c=None_i=None.DotNet6_0.received.txt | 35 -- ...e=Int_c=None_i=None.DotNet7_0.received.txt | 35 -- ...type=Int_c=None_i=None.Net4_8.received.txt | 35 -- ...rectly_type=Int_c=None_i=None.verified.txt | 36 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 49 -- ...SchemaFilter_i=None.DotNet6_0.received.txt | 49 -- ...SchemaFilter_i=None.DotNet7_0.received.txt | 49 -- ...gerSchemaFilter_i=None.Net4_8.received.txt | 49 -- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 50 +- ...SystemTextJson_i=None.Core3_1.received.txt | 49 -- ...stemTextJson_i=None.DotNet6_0.received.txt | 49 -- ...stemTextJson_i=None.DotNet7_0.received.txt | 49 -- ...=SystemTextJson_i=None.Net4_8.received.txt | 49 -- ...e=Int_c=SystemTextJson_i=None.verified.txt | 50 +- ...=TypeConverter_i=None.Core3_1.received.txt | 77 --- ...ypeConverter_i=None.DotNet6_0.received.txt | 77 --- ...ypeConverter_i=None.DotNet7_0.received.txt | 77 --- ...c=TypeConverter_i=None.Net4_8.received.txt | 77 --- ...pe=Int_c=TypeConverter_i=None.verified.txt | 78 +++- ...perTypeHandler_i=None.Core3_1.received.txt | 55 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 55 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 55 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 55 --- ...ng_c=DapperTypeHandler_i=None.verified.txt | 56 ++- ...ValueConverter_i=None.Core3_1.received.txt | 46 -- ...lueConverter_i=None.DotNet6_0.received.txt | 46 -- ...lueConverter_i=None.DotNet7_0.received.txt | 46 -- ...eValueConverter_i=None.Net4_8.received.txt | 46 -- ...c=EfCoreValueConverter_i=None.verified.txt | 47 +- ...NewtonsoftJson_i=None.Core3_1.received.txt | 56 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 56 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 56 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 56 --- ...=Long_c=NewtonsoftJson_i=None.verified.txt | 57 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 36 -- ...=None_i=IComparable.DotNet6_0.received.txt | 36 -- ...=None_i=IComparable.DotNet7_0.received.txt | 36 -- ...g_c=None_i=IComparable.Net4_8.received.txt | 36 -- ...ype=Long_c=None_i=IComparable.verified.txt | 37 +- ...g_c=None_i=IEquatable.Core3_1.received.txt | 35 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 35 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 35 -- ...ng_c=None_i=IEquatable.Net4_8.received.txt | 35 -- ...type=Long_c=None_i=IEquatable.verified.txt | 36 +- ..._type=Long_c=None_i=IParsable.verified.txt | 36 +- ...pe=Long_c=None_i=None.Core3_1.received.txt | 35 -- ...=Long_c=None_i=None.DotNet6_0.received.txt | 35 -- ...=Long_c=None_i=None.DotNet7_0.received.txt | 35 -- ...ype=Long_c=None_i=None.Net4_8.received.txt | 35 -- ...ectly_type=Long_c=None_i=None.verified.txt | 36 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 49 -- ...SchemaFilter_i=None.DotNet6_0.received.txt | 49 -- ...SchemaFilter_i=None.DotNet7_0.received.txt | 49 -- ...gerSchemaFilter_i=None.Net4_8.received.txt | 49 -- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 50 +- ...SystemTextJson_i=None.Core3_1.received.txt | 49 -- ...stemTextJson_i=None.DotNet6_0.received.txt | 49 -- ...stemTextJson_i=None.DotNet7_0.received.txt | 49 -- ...=SystemTextJson_i=None.Net4_8.received.txt | 49 -- ...=Long_c=SystemTextJson_i=None.verified.txt | 50 +- ...=TypeConverter_i=None.Core3_1.received.txt | 79 ---- ...ypeConverter_i=None.DotNet6_0.received.txt | 79 ---- ...ypeConverter_i=None.DotNet7_0.received.txt | 79 ---- ...c=TypeConverter_i=None.Net4_8.received.txt | 79 ---- ...e=Long_c=TypeConverter_i=None.verified.txt | 80 +++- ...perTypeHandler_i=None.Core3_1.received.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 54 --- ...Id_c=DapperTypeHandler_i=None.verified.txt | 55 ++- ...ValueConverter_i=None.Core3_1.received.txt | 47 -- ...lueConverter_i=None.DotNet6_0.received.txt | 47 -- ...lueConverter_i=None.DotNet7_0.received.txt | 47 -- ...eValueConverter_i=None.Net4_8.received.txt | 47 -- ...c=EfCoreValueConverter_i=None.verified.txt | 48 +- ...NewtonsoftJson_i=None.Core3_1.received.txt | 57 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 57 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 57 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 57 --- ...NewId_c=NewtonsoftJson_i=None.verified.txt | 58 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 37 -- ...=None_i=IComparable.DotNet6_0.received.txt | 37 -- ...=None_i=IComparable.DotNet7_0.received.txt | 37 -- ...d_c=None_i=IComparable.Net4_8.received.txt | 37 -- ...sitNewId_c=None_i=IComparable.verified.txt | 38 +- ...d_c=None_i=IEquatable.Core3_1.received.txt | 36 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 36 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 36 -- ...Id_c=None_i=IEquatable.Net4_8.received.txt | 36 -- ...nsitNewId_c=None_i=IEquatable.verified.txt | 37 +- ...ansitNewId_c=None_i=IParsable.verified.txt | 37 +- ...itNewId_c=None_i=None.Core3_1.received.txt | 36 -- ...NewId_c=None_i=None.DotNet6_0.received.txt | 36 -- ...NewId_c=None_i=None.DotNet7_0.received.txt | 36 -- ...sitNewId_c=None_i=None.Net4_8.received.txt | 36 -- ...assTransitNewId_c=None_i=None.verified.txt | 37 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 50 -- ...SchemaFilter_i=None.DotNet6_0.received.txt | 50 -- ...SchemaFilter_i=None.DotNet7_0.received.txt | 50 -- ...gerSchemaFilter_i=None.Net4_8.received.txt | 50 -- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 51 +- ...SystemTextJson_i=None.Core3_1.received.txt | 50 -- ...stemTextJson_i=None.DotNet6_0.received.txt | 50 -- ...stemTextJson_i=None.DotNet7_0.received.txt | 50 -- ...=SystemTextJson_i=None.Net4_8.received.txt | 50 -- ...NewId_c=SystemTextJson_i=None.verified.txt | 51 +- ...=TypeConverter_i=None.Core3_1.received.txt | 86 ---- ...ypeConverter_i=None.DotNet6_0.received.txt | 86 ---- ...ypeConverter_i=None.DotNet7_0.received.txt | 86 ---- ...c=TypeConverter_i=None.Net4_8.received.txt | 86 ---- ...tNewId_c=TypeConverter_i=None.verified.txt | 87 +++- ...perTypeHandler_i=None.Core3_1.received.txt | 63 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 63 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 63 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 63 --- ...ng_c=DapperTypeHandler_i=None.verified.txt | 64 ++- ...ValueConverter_i=None.Core3_1.received.txt | 55 --- ...lueConverter_i=None.DotNet6_0.received.txt | 55 --- ...lueConverter_i=None.DotNet7_0.received.txt | 55 --- ...eValueConverter_i=None.Net4_8.received.txt | 55 --- ...c=EfCoreValueConverter_i=None.verified.txt | 56 ++- ...NewtonsoftJson_i=None.Core3_1.received.txt | 71 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 71 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 71 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 71 --- ...tring_c=NewtonsoftJson_i=None.verified.txt | 72 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 54 --- ...=None_i=IComparable.DotNet6_0.received.txt | 54 --- ...=None_i=IComparable.DotNet7_0.received.txt | 54 --- ...g_c=None_i=IComparable.Net4_8.received.txt | 54 --- ...leString_c=None_i=IComparable.verified.txt | 55 ++- ...g_c=None_i=IEquatable.Core3_1.received.txt | 44 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 44 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 44 -- ...ng_c=None_i=IEquatable.Net4_8.received.txt | 44 -- ...bleString_c=None_i=IEquatable.verified.txt | 45 +- ...ableString_c=None_i=IParsable.verified.txt | 45 +- ...eString_c=None_i=None.Core3_1.received.txt | 44 -- ...tring_c=None_i=None.DotNet6_0.received.txt | 44 -- ...tring_c=None_i=None.DotNet7_0.received.txt | 44 -- ...leString_c=None_i=None.Net4_8.received.txt | 44 -- ...=NullableString_c=None_i=None.verified.txt | 45 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 59 --- ...SchemaFilter_i=None.DotNet6_0.received.txt | 59 --- ...SchemaFilter_i=None.DotNet7_0.received.txt | 59 --- ...gerSchemaFilter_i=None.Net4_8.received.txt | 59 --- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 60 ++- ...SystemTextJson_i=None.Core3_1.received.txt | 65 --- ...stemTextJson_i=None.DotNet6_0.received.txt | 65 --- ...stemTextJson_i=None.DotNet7_0.received.txt | 65 --- ...=SystemTextJson_i=None.Net4_8.received.txt | 65 --- ...tring_c=SystemTextJson_i=None.verified.txt | 66 ++- ...=TypeConverter_i=None.Core3_1.received.txt | 87 ---- ...ypeConverter_i=None.DotNet6_0.received.txt | 87 ---- ...ypeConverter_i=None.DotNet7_0.received.txt | 87 ---- ...c=TypeConverter_i=None.Net4_8.received.txt | 87 ---- ...String_c=TypeConverter_i=None.verified.txt | 88 +++- ...perTypeHandler_i=None.Core3_1.received.txt | 61 --- ...rTypeHandler_i=None.DotNet6_0.received.txt | 61 --- ...rTypeHandler_i=None.DotNet7_0.received.txt | 61 --- ...pperTypeHandler_i=None.Net4_8.received.txt | 61 --- ...ng_c=DapperTypeHandler_i=None.verified.txt | 62 ++- ...ValueConverter_i=None.Core3_1.received.txt | 55 --- ...lueConverter_i=None.DotNet6_0.received.txt | 55 --- ...lueConverter_i=None.DotNet7_0.received.txt | 55 --- ...eValueConverter_i=None.Net4_8.received.txt | 55 --- ...c=EfCoreValueConverter_i=None.verified.txt | 56 ++- ...NewtonsoftJson_i=None.Core3_1.received.txt | 71 --- ...wtonsoftJson_i=None.DotNet6_0.received.txt | 71 --- ...wtonsoftJson_i=None.DotNet7_0.received.txt | 71 --- ...=NewtonsoftJson_i=None.Net4_8.received.txt | 71 --- ...tring_c=NewtonsoftJson_i=None.verified.txt | 72 ++- ..._c=None_i=IComparable.Core3_1.received.txt | 54 --- ...=None_i=IComparable.DotNet6_0.received.txt | 54 --- ...=None_i=IComparable.DotNet7_0.received.txt | 54 --- ...g_c=None_i=IComparable.Net4_8.received.txt | 54 --- ...e=String_c=None_i=IComparable.verified.txt | 55 ++- ...g_c=None_i=IEquatable.Core3_1.received.txt | 44 -- ...c=None_i=IEquatable.DotNet6_0.received.txt | 44 -- ...c=None_i=IEquatable.DotNet7_0.received.txt | 44 -- ...ng_c=None_i=IEquatable.Net4_8.received.txt | 44 -- ...pe=String_c=None_i=IEquatable.verified.txt | 45 +- ...ype=String_c=None_i=IParsable.verified.txt | 45 +- ...=String_c=None_i=None.Core3_1.received.txt | 44 -- ...tring_c=None_i=None.DotNet6_0.received.txt | 44 -- ...tring_c=None_i=None.DotNet7_0.received.txt | 44 -- ...e=String_c=None_i=None.Net4_8.received.txt | 44 -- ...tly_type=String_c=None_i=None.verified.txt | 45 +- ...erSchemaFilter_i=None.Core3_1.received.txt | 59 --- ...SchemaFilter_i=None.DotNet6_0.received.txt | 59 --- ...SchemaFilter_i=None.DotNet7_0.received.txt | 59 --- ...gerSchemaFilter_i=None.Net4_8.received.txt | 59 --- ..._c=SwaggerSchemaFilter_i=None.verified.txt | 60 ++- ...SystemTextJson_i=None.Core3_1.received.txt | 58 --- ...stemTextJson_i=None.DotNet6_0.received.txt | 58 --- ...stemTextJson_i=None.DotNet7_0.received.txt | 58 --- ...=SystemTextJson_i=None.Net4_8.received.txt | 58 --- ...tring_c=SystemTextJson_i=None.verified.txt | 59 ++- ...=TypeConverter_i=None.Core3_1.received.txt | 82 ---- ...ypeConverter_i=None.DotNet6_0.received.txt | 82 ---- ...ypeConverter_i=None.DotNet7_0.received.txt | 82 ---- ...c=TypeConverter_i=None.Net4_8.received.txt | 82 ---- ...String_c=TypeConverter_i=None.verified.txt | 83 +++- ...ly_nestedClassCount=0.Core3_1.received.txt | 56 --- ..._nestedClassCount=0.DotNet6_0.received.txt | 56 --- ..._nestedClassCount=0.DotNet7_0.received.txt | 56 --- ...tly_nestedClassCount=0.Net4_8.received.txt | 56 --- ...sCorrectly_nestedClassCount=0.verified.txt | 57 ++- ...ly_nestedClassCount=1.Core3_1.received.txt | 59 --- ..._nestedClassCount=1.DotNet6_0.received.txt | 59 --- ..._nestedClassCount=1.DotNet7_0.received.txt | 59 --- ...tly_nestedClassCount=1.Net4_8.received.txt | 59 --- ...sCorrectly_nestedClassCount=1.verified.txt | 60 ++- ...ly_nestedClassCount=2.Core3_1.received.txt | 62 --- ..._nestedClassCount=2.DotNet6_0.received.txt | 62 --- ..._nestedClassCount=2.DotNet7_0.received.txt | 62 --- ...tly_nestedClassCount=2.Net4_8.received.txt | 62 --- ...sCorrectly_nestedClassCount=2.verified.txt | 63 ++- ...ltIdInGlobalNamespace.Core3_1.verified.txt | 333 +++++++++++++ ...IdInGlobalNamespace.DotNet6_0.verified.txt | 333 +++++++++++++ ...IdInGlobalNamespace.DotNet7_0.verified.txt | 333 +++++++++++++ ...ultIdInGlobalNamespace.Net4_8.verified.txt | 333 +++++++++++++ ...ateDefaultIdInGlobalNamespace.verified.txt | 334 ++++++++++++- ...InFileScopedNamespace.Core3_1.verified.txt | 336 +++++++++++++ ...FileScopedNamespace.DotNet6_0.verified.txt | 336 +++++++++++++ ...FileScopedNamespace.DotNet7_0.verified.txt | 336 +++++++++++++ ...dInFileScopedNamespace.Net4_8.verified.txt | 336 +++++++++++++ ...nerateIdInFileScopedNamespace.verified.txt | 337 ++++++++++++- ...GenerateIdInNamespace.Core3_1.verified.txt | 336 +++++++++++++ ...nerateIdInNamespace.DotNet6_0.verified.txt | 336 +++++++++++++ ...nerateIdInNamespace.DotNet7_0.verified.txt | 336 +++++++++++++ ...nGenerateIdInNamespace.Net4_8.verified.txt | 336 +++++++++++++ ...ests.CanGenerateIdInNamespace.verified.txt | 337 ++++++++++++- ...tJson, SystemTextJson.Core3_1.verified.txt | 308 ++++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 308 ++++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 308 ++++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 308 ++++++++++++ ...ewtonsoftJson, SystemTextJson.verified.txt | 309 +++++++++++- ...verter=NewtonsoftJson.Core3_1.verified.txt | 294 ++++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 294 ++++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 294 ++++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 294 ++++++++++++ ...Guid_converter=NewtonsoftJson.verified.txt | 295 +++++++++++- ...verter=SystemTextJson.Core3_1.verified.txt | 287 ++++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 287 ++++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 287 ++++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 287 ++++++++++++ ...Guid_converter=SystemTextJson.verified.txt | 288 +++++++++++- ...nverter=TypeConverter.Core3_1.verified.txt | 315 +++++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 315 +++++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 315 +++++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 315 +++++++++++++ ...=Guid_converter=TypeConverter.verified.txt | 316 ++++++++++++- ...e=Guid_converter=null.Core3_1.verified.txt | 336 +++++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 336 +++++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 336 +++++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 336 +++++++++++++ ...ckingType=Guid_converter=null.verified.txt | 337 ++++++++++++- ...tJson, SystemTextJson.Core3_1.verified.txt | 308 ++++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 308 ++++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 308 ++++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 308 ++++++++++++ ...ewtonsoftJson, SystemTextJson.verified.txt | 309 +++++++++++- ...verter=NewtonsoftJson.Core3_1.verified.txt | 294 ++++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 294 ++++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 294 ++++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 294 ++++++++++++ ...Guid_converter=NewtonsoftJson.verified.txt | 295 +++++++++++- ...verter=SystemTextJson.Core3_1.verified.txt | 287 ++++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 287 ++++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 287 ++++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 287 ++++++++++++ ...Guid_converter=SystemTextJson.verified.txt | 288 +++++++++++- ...nverter=TypeConverter.Core3_1.verified.txt | 315 +++++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 315 +++++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 315 +++++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 315 +++++++++++++ ...=Guid_converter=TypeConverter.verified.txt | 316 ++++++++++++- ...e=Guid_converter=null.Core3_1.verified.txt | 336 +++++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 336 +++++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 336 +++++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 336 +++++++++++++ ...ckingType=Guid_converter=null.verified.txt | 337 ++++++++++++- ...ltipleIdsWithSameName.Core3_1.verified.txt | 440 +++++++++++++++++ ...ipleIdsWithSameName.DotNet6_0.verified.txt | 440 +++++++++++++++++ ...ipleIdsWithSameName.DotNet7_0.verified.txt | 440 +++++++++++++++++ ...ultipleIdsWithSameName.Net4_8.verified.txt | 440 +++++++++++++++++ ...nerateMultipleIdsWithSameName.verified.txt | 441 +++++++++++++++++- ...dInFileScopeNamespace.Core3_1.verified.txt | 339 ++++++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 339 ++++++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 339 ++++++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 339 ++++++++++++++ ...eNestedIdInFileScopeNamespace.verified.txt | 340 +++++++++++++- ...dInFileScopeNamespace.Core3_1.verified.txt | 345 ++++++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 345 ++++++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 345 ++++++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 345 ++++++++++++++ ...yNestedIdInFileScopeNamespace.verified.txt | 346 +++++++++++++- ...sUsingGlobalAttribute.Core3_1.verified.txt | 269 +++++++++++ ...singGlobalAttribute.DotNet6_0.verified.txt | 269 +++++++++++ ...singGlobalAttribute.DotNet7_0.verified.txt | 269 +++++++++++ ...tsUsingGlobalAttribute.Net4_8.verified.txt | 269 +++++++++++ ...eDefaultsUsingGlobalAttribute.verified.txt | 270 ++++++++++- 455 files changed, 32865 insertions(+), 16223 deletions(-) rename test/StronglyTypedIds.Tests/Snapshots/{EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt => EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt => EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt} (100%) rename test/StronglyTypedIds.Tests/Snapshots/{EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt => EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt} (100%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt => EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt} (100%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.received.txt rename to test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.received.txt rename to test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.received.txt rename to test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt index 5f282702b..58a2c4794 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.verified.txt @@ -1 +1,62 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt index 5f282702b..4ea1be319 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt index 5f282702b..f9fffe68a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.verified.txt @@ -1 +1,70 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt index 5f282702b..3df9e2e31 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.verified.txt @@ -1 +1,60 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt similarity index 100% rename from test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.received.txt rename to test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt new file mode 100644 index 000000000..fec04c8e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt new file mode 100644 index 000000000..fec04c8e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt new file mode 100644 index 000000000..fec04c8e1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt index 5f282702b..fec04c8e1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt @@ -1 +1,60 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 806d124ae..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt index 806d124ae..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 806d124ae..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt index 806d124ae..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 5f282702b..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -1 +1,157 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index 95c5442ae..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt index 95c5442ae..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 95c5442ae..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.received.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt index 95c5442ae..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index 5f282702b..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -1 +1,157 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.received.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index 3fa5fad11..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.received.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt index 3fa5fad11..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.received.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 3fa5fad11..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.received.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt index 3fa5fad11..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 5f282702b..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -1 +1,160 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.received.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt index 52fddbd6a..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.received.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt index 52fddbd6a..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.received.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index 52fddbd6a..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.received.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt index 52fddbd6a..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index 5f282702b..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -1 +1,165 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.received.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt index 147d4c700..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.received.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt index 147d4c700..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.received.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index 147d4c700..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.received.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt index 147d4c700..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index 5f282702b..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -1 +1,190 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.received.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt index 2d01666a6..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.received.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt index 2d01666a6..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.received.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 2d01666a6..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.received.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt index 2d01666a6..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 5f282702b..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -1 +1,176 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..bb6b344ab 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,54 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..508208c37 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,47 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..db59f66c1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,57 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt index 5f282702b..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt @@ -1 +1,37 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt index 5f282702b..a13e9bec6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index 5f282702b..92cda7756 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt index 5f282702b..fad5ea0b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..f72224715 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,50 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt index 5f282702b..d6d801a99 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt @@ -1 +1,50 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt index 5f282702b..295e92baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt @@ -1 +1,78 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..f8d24bbf5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,54 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..d3e50467b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,46 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..b4d9738e7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,56 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt index 5f282702b..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt index 5f282702b..5d23b64a1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index 5f282702b..e8afb0e98 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt index 5f282702b..45272d34a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..297090ba1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,49 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt index 5f282702b..7c016c3be 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt @@ -1 +1,49 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt index 5f282702b..39f1e9331 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt @@ -1 +1,77 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..35fd482b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,55 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..cb5754863 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,46 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..7052a3b27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,56 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt index 5f282702b..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt index 5f282702b..13b9b1ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 5f282702b..9b553ad33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt index 5f282702b..af1658c35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt @@ -1 +1,35 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..72b024dca 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,49 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt index 5f282702b..17a45333f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt @@ -1 +1,49 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt index 5f282702b..e22d0478c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt @@ -1 +1,79 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..23efe4b09 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,54 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..9114f2d54 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,47 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..181d85e44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,57 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt index 5f282702b..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt @@ -1 +1,37 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt index 5f282702b..b4c2d5867 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index 5f282702b..8898353da 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt index 5f282702b..7e4892f41 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt @@ -1 +1,36 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..699828755 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,50 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt index 5f282702b..3de0600ab 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt @@ -1 +1,50 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt index 5f282702b..757eb4ebb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt @@ -1 +1,86 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..c96f1e168 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,63 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..e1a174104 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,55 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..9660c1fc0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,71 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt index 5f282702b..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt @@ -1 +1,54 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt index 5f282702b..bb2e2c7d2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index 5f282702b..8a440b779 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt index 5f282702b..fe1e43665 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..c85338e9a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,59 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt index 5f282702b..c049fb7f5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt @@ -1 +1,65 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt index 5f282702b..50b3c0585 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt @@ -1 +1,87 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.received.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.received.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt index 5f282702b..749dd1dbd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt @@ -1 +1,61 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt index 5f282702b..05700f78d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt @@ -1 +1,55 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt index 5f282702b..d7596bf2b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt @@ -1 +1,71 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.received.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt index 5f282702b..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt @@ -1 +1,54 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt index 5f282702b..050bcc20b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index 5f282702b..3ce01566b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt index 5f282702b..0987c7d64 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt @@ -1 +1,44 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt index 5f282702b..6e4590319 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt @@ -1 +1,59 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.received.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.received.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt index 5f282702b..1396ccae3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt @@ -1 +1,58 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.received.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.received.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.received.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.received.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt index 5f282702b..d35ac20a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt @@ -1 +1,82 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.received.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt index 5f282702b..ff61cdde7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt @@ -1 +1,56 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.received.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt index 5f282702b..dacf3158c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt @@ -1 +1,59 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.received.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.received.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.received.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.received.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt index 5f282702b..b71458e7e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt @@ -1 +1,62 @@ - \ No newline at end of file +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..12bc7a92a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt @@ -0,0 +1,333 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..12bc7a92a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt @@ -0,0 +1,333 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..12bc7a92a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt @@ -0,0 +1,333 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..12bc7a92a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt @@ -0,0 +1,333 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 5f282702b..12bc7a92a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -1 +1,333 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 5f282702b..09e26fecf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -1 +1,336 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..09e26fecf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 5f282702b..09e26fecf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -1 +1,336 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 5f282702b..bc83b2a93 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -1 +1,308 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 5f282702b..a71f4a25e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -1 +1,294 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 5f282702b..da5f95855 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -1 +1,287 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 5f282702b..9502b5987 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -1 +1,315 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index 5f282702b..d9c815c35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -1 +1,336 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..bc83b2a93 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,308 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 5f282702b..bc83b2a93 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -1 +1,308 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt new file mode 100644 index 000000000..a71f4a25e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -0,0 +1,294 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 5f282702b..a71f4a25e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -1 +1,294 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..da5f95855 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,287 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 5f282702b..da5f95855 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -1 +1,287 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt new file mode 100644 index 000000000..9502b5987 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -0,0 +1,315 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 5f282702b..9502b5987 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -1 +1,315 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt new file mode 100644 index 000000000..d9c815c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -0,0 +1,336 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index 5f282702b..d9c815c35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -1 +1,336 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt new file mode 100644 index 000000000..ccf413db8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt @@ -0,0 +1,440 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt new file mode 100644 index 000000000..ccf413db8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt @@ -0,0 +1,440 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt new file mode 100644 index 000000000..ccf413db8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt @@ -0,0 +1,440 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt new file mode 100644 index 000000000..ccf413db8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt @@ -0,0 +1,440 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index 5f282702b..ccf413db8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -1 +1,440 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..3a5d8d449 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -0,0 +1,339 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..3a5d8d449 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -0,0 +1,339 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..3a5d8d449 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -0,0 +1,339 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..3a5d8d449 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -0,0 +1,339 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 5f282702b..3a5d8d449 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -1 +1,339 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..96dfba11f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -0,0 +1,345 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..96dfba11f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -0,0 +1,345 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..96dfba11f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -0,0 +1,345 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..96dfba11f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -0,0 +1,345 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index 5f282702b..96dfba11f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -1 +1,345 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt new file mode 100644 index 000000000..98786ec30 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt @@ -0,0 +1,269 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt new file mode 100644 index 000000000..98786ec30 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt @@ -0,0 +1,269 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt new file mode 100644 index 000000000..98786ec30 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt @@ -0,0 +1,269 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..98786ec30 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt @@ -0,0 +1,269 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index 5f282702b..98786ec30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -1 +1,269 @@ - \ No newline at end of file +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + #if NET7_0_OR_GREATER + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8, + #endif + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } From 8bc80c5edefdd1f145b6ec4eff93f4ec95d1720e Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 17:27:39 +0300 Subject: [PATCH 20/37] version --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 716d80ec4..2a29ab3f8 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.2 + 1.0.3 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 5cac9701934a7f931e4e5b02224bbae2b89f15e6 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 18:03:35 +0300 Subject: [PATCH 21/37] net7/netstandart --- StronglyTypedId.sln | 1 + .../StronglyTypedIds.Attributes.csproj | 2 +- src/StronglyTypedIds/StronglyTypedIds.csproj | 2 +- version.props | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/StronglyTypedId.sln b/StronglyTypedId.sln index 81f0a188c..39ac8adc9 100644 --- a/StronglyTypedId.sln +++ b/StronglyTypedId.sln @@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CHANGELOG.md = CHANGELOG.md build.sh = build.sh NuGet.integration-tests.config = NuGet.integration-tests.config + global.json = global.json EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}" diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj index 5fd0485d3..dfa2dcd98 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;;net7.0 enable StronglyTypedIds false diff --git a/src/StronglyTypedIds/StronglyTypedIds.csproj b/src/StronglyTypedIds/StronglyTypedIds.csproj index b3cd8e94d..cdd8d2cc8 100644 --- a/src/StronglyTypedIds/StronglyTypedIds.csproj +++ b/src/StronglyTypedIds/StronglyTypedIds.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;net7.0 false enable Tennisi.StronglyTypedId diff --git a/version.props b/version.props index 2a29ab3f8..44d14f703 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.3 + 1.0.4 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 10f459728111d8cd9f3daf7d8f8a40163625bc10 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Mon, 13 Mar 2023 18:18:33 +0300 Subject: [PATCH 22/37] tests --- ...Correctly_type=Guid.DotNet7_0.verified.txt | 2 +- ...atesFullIdCorrectly_type=Guid.verified.txt | 2 +- ...dCorrectly_type=Int.DotNet7_0.verified.txt | 2 +- ...ratesFullIdCorrectly_type=Int.verified.txt | 2 +- ...Correctly_type=Long.DotNet7_0.verified.txt | 2 +- ...atesFullIdCorrectly_type=Long.verified.txt | 2 +- ...pe=MassTransitNewId.DotNet7_0.verified.txt | 2 +- ...rrectly_type=MassTransitNewId.verified.txt | 2 +- ...type=NullableString.DotNet7_0.verified.txt | 2 +- ...Correctly_type=NullableString.verified.txt | 2 +- ...rrectly_type=String.DotNet7_0.verified.txt | 2 +- ...esFullIdCorrectly_type=String.verified.txt | 2 +- ..._c=None_i=IParsable.DotNet7_0.received.txt | 36 --------------- ..._c=None_i=IParsable.DotNet7_0.received.txt | 35 --------------- ..._c=None_i=IParsable.DotNet7_0.received.txt | 35 --------------- ..._c=None_i=IParsable.DotNet7_0.received.txt | 36 --------------- ..._c=None_i=IParsable.DotNet7_0.received.txt | 44 ------------------- ..._c=None_i=IParsable.DotNet7_0.received.txt | 44 ------------------- 18 files changed, 12 insertions(+), 242 deletions(-) delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 7ee4bd7d4..806d124ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 7ee4bd7d4..806d124ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index d65d51495..95c5442ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index d65d51495..95c5442ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 09643c593..3fa5fad11 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 09643c593..3fa5fad11 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index caa78ba07..52fddbd6a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index caa78ba07..52fddbd6a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index b45ca58f8..147d4c700 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index b45ca58f8..147d4c700 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 8612d81b5..2d01666a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 8612d81b5..2d01666a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } From 0fc54848be2b7f2ebd605661f4728365a36f9e9e Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 02:54:05 +0300 Subject: [PATCH 23/37] parsable tests --- .../StronglyTypedIdImplementations.cs | 4 +- .../StronglyTypedIds.Attributes.csproj | 2 +- src/StronglyTypedIds/StronglyTypedIds.csproj | 2 +- .../Templates/Guid/Guid_Parsable.cs | 7 +- .../Templates/Int/Int_Parsable.cs | 7 +- .../Templates/Long/Long_Parsable.cs | 7 +- ...onglyTypedIdAttribute.Core3_1.verified.txt | 62 --- ...glyTypedIdAttribute.DotNet6_0.verified.txt | 62 --- ...glyTypedIdAttribute.DotNet7_0.verified.txt | 62 --- ...ronglyTypedIdAttribute.Net4_8.verified.txt | 62 --- ...glyTypedIdBackingType.Core3_1.verified.txt | 36 -- ...yTypedIdBackingType.DotNet6_0.verified.txt | 36 -- ...yTypedIdBackingType.DotNet7_0.verified.txt | 36 -- ...nglyTypedIdBackingType.Net4_8.verified.txt | 36 -- ...onglyTypedIdConverter.Core3_1.verified.txt | 70 --- ...glyTypedIdConverter.DotNet6_0.verified.txt | 70 --- ...glyTypedIdConverter.DotNet7_0.verified.txt | 70 --- ...ronglyTypedIdConverter.Net4_8.verified.txt | 70 --- ...edIdDefaultsAttribute.Core3_1.verified.txt | 60 --- ...IdDefaultsAttribute.DotNet6_0.verified.txt | 60 --- ...IdDefaultsAttribute.DotNet7_0.verified.txt | 60 --- ...pedIdDefaultsAttribute.Net4_8.verified.txt | 60 --- ...ypedIdImplementations.Core3_1.verified.txt | 60 --- ...edIdImplementations.DotNet6_0.verified.txt | 60 --- ...edIdImplementations.DotNet7_0.verified.txt | 60 --- ...TypedIdImplementations.Net4_8.verified.txt | 60 --- ...tronglyTypedIdImplementations.verified.txt | 4 +- ...IdCorrectly_type=Guid.Core3_1.verified.txt | 157 ------- ...Correctly_type=Guid.DotNet6_0.verified.txt | 157 ------- ...Correctly_type=Guid.DotNet7_0.verified.txt | 2 +- ...lIdCorrectly_type=Guid.Net4_8.verified.txt | 157 ------- ...atesFullIdCorrectly_type=Guid.verified.txt | 157 ------- ...lIdCorrectly_type=Int.Core3_1.verified.txt | 157 ------- ...dCorrectly_type=Int.DotNet6_0.verified.txt | 157 ------- ...dCorrectly_type=Int.DotNet7_0.verified.txt | 2 +- ...llIdCorrectly_type=Int.Net4_8.verified.txt | 157 ------- ...ratesFullIdCorrectly_type=Int.verified.txt | 157 ------- ...IdCorrectly_type=Long.Core3_1.verified.txt | 160 ------- ...Correctly_type=Long.DotNet6_0.verified.txt | 160 ------- ...Correctly_type=Long.DotNet7_0.verified.txt | 2 +- ...lIdCorrectly_type=Long.Net4_8.verified.txt | 160 ------- ...atesFullIdCorrectly_type=Long.verified.txt | 160 ------- ...type=MassTransitNewId.Core3_1.verified.txt | 165 ------- ...pe=MassTransitNewId.DotNet6_0.verified.txt | 165 ------- ...pe=MassTransitNewId.DotNet7_0.verified.txt | 2 +- ..._type=MassTransitNewId.Net4_8.verified.txt | 165 ------- ...rrectly_type=MassTransitNewId.verified.txt | 165 ------- ...y_type=NullableString.Core3_1.verified.txt | 190 -------- ...type=NullableString.DotNet6_0.verified.txt | 190 -------- ...type=NullableString.DotNet7_0.verified.txt | 2 +- ...ly_type=NullableString.Net4_8.verified.txt | 190 -------- ...Correctly_type=NullableString.verified.txt | 190 -------- ...Correctly_type=String.Core3_1.verified.txt | 176 ------- ...rrectly_type=String.DotNet6_0.verified.txt | 176 ------- ...rrectly_type=String.DotNet7_0.verified.txt | 2 +- ...dCorrectly_type=String.Net4_8.verified.txt | 176 ------- ...esFullIdCorrectly_type=String.verified.txt | 176 ------- ...perTypeHandler_i=None.Core3_1.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 --- ...ValueConverter_i=None.Core3_1.verified.txt | 47 -- ...lueConverter_i=None.DotNet6_0.verified.txt | 47 -- ...lueConverter_i=None.DotNet7_0.verified.txt | 47 -- ...eValueConverter_i=None.Net4_8.verified.txt | 47 -- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 37 -- ...=None_i=IComparable.DotNet6_0.verified.txt | 37 -- ...=None_i=IComparable.DotNet7_0.verified.txt | 37 -- ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 -- ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 -- ...id_c=None_i=IEquatable.Net4_8.verified.txt | 36 -- ...id_c=None_i=IParsable.Core3_1.received.txt | 36 -- ...id_c=None_i=IParsable.Core3_1.verified.txt | 36 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 36 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 -- ...uid_c=None_i=IParsable.Net4_8.received.txt | 36 -- ...uid_c=None_i=IParsable.Net4_8.verified.txt | 36 -- ..._type=Guid_c=None_i=IParsable.verified.txt | 2 +- ...pe=Guid_c=None_i=None.Core3_1.verified.txt | 36 -- ...=Guid_c=None_i=None.DotNet6_0.verified.txt | 36 -- ...=Guid_c=None_i=None.DotNet7_0.verified.txt | 36 -- ...ype=Guid_c=None_i=None.Net4_8.verified.txt | 36 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 -- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 -- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 -- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 -- ...SystemTextJson_i=None.Core3_1.verified.txt | 50 -- ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 -- ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 -- ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 -- ...=TypeConverter_i=None.Core3_1.verified.txt | 78 ---- ...ypeConverter_i=None.DotNet6_0.verified.txt | 78 ---- ...ypeConverter_i=None.DotNet7_0.verified.txt | 78 ---- ...c=TypeConverter_i=None.Net4_8.verified.txt | 78 ---- ...perTypeHandler_i=None.Core3_1.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 --- ...ValueConverter_i=None.Core3_1.verified.txt | 46 -- ...lueConverter_i=None.DotNet6_0.verified.txt | 46 -- ...lueConverter_i=None.DotNet7_0.verified.txt | 46 -- ...eValueConverter_i=None.Net4_8.verified.txt | 46 -- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 36 -- ...=None_i=IComparable.DotNet6_0.verified.txt | 36 -- ...=None_i=IComparable.DotNet7_0.verified.txt | 36 -- ...t_c=None_i=IComparable.Net4_8.verified.txt | 36 -- ...t_c=None_i=IEquatable.Core3_1.verified.txt | 35 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 -- ...nt_c=None_i=IEquatable.Net4_8.verified.txt | 35 -- ...nt_c=None_i=IParsable.Core3_1.received.txt | 35 -- ...nt_c=None_i=IParsable.Core3_1.verified.txt | 35 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 35 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 -- ...Int_c=None_i=IParsable.Net4_8.received.txt | 35 -- ...Int_c=None_i=IParsable.Net4_8.verified.txt | 35 -- ...y_type=Int_c=None_i=IParsable.verified.txt | 2 +- ...ype=Int_c=None_i=None.Core3_1.verified.txt | 35 -- ...e=Int_c=None_i=None.DotNet6_0.verified.txt | 35 -- ...e=Int_c=None_i=None.DotNet7_0.verified.txt | 35 -- ...type=Int_c=None_i=None.Net4_8.verified.txt | 35 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 -- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 -- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 -- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 -- ...SystemTextJson_i=None.Core3_1.verified.txt | 49 -- ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 -- ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 -- ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 -- ...=TypeConverter_i=None.Core3_1.verified.txt | 77 --- ...ypeConverter_i=None.DotNet6_0.verified.txt | 77 --- ...ypeConverter_i=None.DotNet7_0.verified.txt | 77 --- ...c=TypeConverter_i=None.Net4_8.verified.txt | 77 --- ...perTypeHandler_i=None.Core3_1.verified.txt | 55 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 55 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 55 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 55 --- ...ValueConverter_i=None.Core3_1.verified.txt | 46 -- ...lueConverter_i=None.DotNet6_0.verified.txt | 46 -- ...lueConverter_i=None.DotNet7_0.verified.txt | 46 -- ...eValueConverter_i=None.Net4_8.verified.txt | 46 -- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 36 -- ...=None_i=IComparable.DotNet6_0.verified.txt | 36 -- ...=None_i=IComparable.DotNet7_0.verified.txt | 36 -- ...g_c=None_i=IComparable.Net4_8.verified.txt | 36 -- ...g_c=None_i=IEquatable.Core3_1.verified.txt | 35 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 -- ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 35 -- ...ng_c=None_i=IParsable.Core3_1.received.txt | 35 -- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 35 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 35 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 -- ...ong_c=None_i=IParsable.Net4_8.received.txt | 35 -- ...ong_c=None_i=IParsable.Net4_8.verified.txt | 35 -- ..._type=Long_c=None_i=IParsable.verified.txt | 2 +- ...pe=Long_c=None_i=None.Core3_1.verified.txt | 35 -- ...=Long_c=None_i=None.DotNet6_0.verified.txt | 35 -- ...=Long_c=None_i=None.DotNet7_0.verified.txt | 35 -- ...ype=Long_c=None_i=None.Net4_8.verified.txt | 35 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 -- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 -- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 -- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 -- ...SystemTextJson_i=None.Core3_1.verified.txt | 49 -- ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 -- ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 -- ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 -- ...=TypeConverter_i=None.Core3_1.verified.txt | 79 ---- ...ypeConverter_i=None.DotNet6_0.verified.txt | 79 ---- ...ypeConverter_i=None.DotNet7_0.verified.txt | 79 ---- ...c=TypeConverter_i=None.Net4_8.verified.txt | 79 ---- ...perTypeHandler_i=None.Core3_1.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 --- ...ValueConverter_i=None.Core3_1.verified.txt | 47 -- ...lueConverter_i=None.DotNet6_0.verified.txt | 47 -- ...lueConverter_i=None.DotNet7_0.verified.txt | 47 -- ...eValueConverter_i=None.Net4_8.verified.txt | 47 -- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 37 -- ...=None_i=IComparable.DotNet6_0.verified.txt | 37 -- ...=None_i=IComparable.DotNet7_0.verified.txt | 37 -- ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 -- ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 -- ...Id_c=None_i=IEquatable.Net4_8.verified.txt | 36 -- ...Id_c=None_i=IParsable.Core3_1.received.txt | 36 -- ...Id_c=None_i=IParsable.Core3_1.verified.txt | 36 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 36 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 -- ...wId_c=None_i=IParsable.Net4_8.received.txt | 36 -- ...wId_c=None_i=IParsable.Net4_8.verified.txt | 36 -- ...ansitNewId_c=None_i=IParsable.verified.txt | 2 +- ...itNewId_c=None_i=None.Core3_1.verified.txt | 36 -- ...NewId_c=None_i=None.DotNet6_0.verified.txt | 36 -- ...NewId_c=None_i=None.DotNet7_0.verified.txt | 36 -- ...sitNewId_c=None_i=None.Net4_8.verified.txt | 36 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 -- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 -- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 -- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 -- ...SystemTextJson_i=None.Core3_1.verified.txt | 50 -- ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 -- ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 -- ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 -- ...=TypeConverter_i=None.Core3_1.verified.txt | 86 ---- ...ypeConverter_i=None.DotNet6_0.verified.txt | 86 ---- ...ypeConverter_i=None.DotNet7_0.verified.txt | 86 ---- ...c=TypeConverter_i=None.Net4_8.verified.txt | 86 ---- ...perTypeHandler_i=None.Core3_1.verified.txt | 63 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 63 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 63 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 63 --- ...ValueConverter_i=None.Core3_1.verified.txt | 55 --- ...lueConverter_i=None.DotNet6_0.verified.txt | 55 --- ...lueConverter_i=None.DotNet7_0.verified.txt | 55 --- ...eValueConverter_i=None.Net4_8.verified.txt | 55 --- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 54 --- ...=None_i=IComparable.DotNet6_0.verified.txt | 54 --- ...=None_i=IComparable.DotNet7_0.verified.txt | 54 --- ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 --- ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 -- ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 -- ...ng_c=None_i=IParsable.Core3_1.received.txt | 44 -- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 44 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 -- ...ing_c=None_i=IParsable.Net4_8.received.txt | 44 -- ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 -- ...ableString_c=None_i=IParsable.verified.txt | 2 +- ...eString_c=None_i=None.Core3_1.verified.txt | 44 -- ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 -- ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 -- ...leString_c=None_i=None.Net4_8.verified.txt | 44 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 --- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 --- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 --- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 --- ...SystemTextJson_i=None.Core3_1.verified.txt | 65 --- ...stemTextJson_i=None.DotNet6_0.verified.txt | 65 --- ...stemTextJson_i=None.DotNet7_0.verified.txt | 65 --- ...=SystemTextJson_i=None.Net4_8.verified.txt | 65 --- ...=TypeConverter_i=None.Core3_1.verified.txt | 87 ---- ...ypeConverter_i=None.DotNet6_0.verified.txt | 87 ---- ...ypeConverter_i=None.DotNet7_0.verified.txt | 87 ---- ...c=TypeConverter_i=None.Net4_8.verified.txt | 87 ---- ...perTypeHandler_i=None.Core3_1.verified.txt | 61 --- ...rTypeHandler_i=None.DotNet6_0.verified.txt | 61 --- ...rTypeHandler_i=None.DotNet7_0.verified.txt | 61 --- ...pperTypeHandler_i=None.Net4_8.verified.txt | 61 --- ...ValueConverter_i=None.Core3_1.verified.txt | 55 --- ...lueConverter_i=None.DotNet6_0.verified.txt | 55 --- ...lueConverter_i=None.DotNet7_0.verified.txt | 55 --- ...eValueConverter_i=None.Net4_8.verified.txt | 55 --- ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 --- ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 --- ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 --- ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 --- ..._c=None_i=IComparable.Core3_1.verified.txt | 54 --- ...=None_i=IComparable.DotNet6_0.verified.txt | 54 --- ...=None_i=IComparable.DotNet7_0.verified.txt | 54 --- ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 --- ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 -- ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 -- ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 -- ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 -- ...ng_c=None_i=IParsable.Core3_1.received.txt | 44 -- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 -- ..._c=None_i=IParsable.DotNet6_0.received.txt | 44 -- ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 -- ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 -- ...ing_c=None_i=IParsable.Net4_8.received.txt | 44 -- ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 -- ...ype=String_c=None_i=IParsable.verified.txt | 2 +- ...=String_c=None_i=None.Core3_1.verified.txt | 44 -- ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 -- ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 -- ...e=String_c=None_i=None.Net4_8.verified.txt | 44 -- ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 --- ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 --- ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 --- ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 --- ...SystemTextJson_i=None.Core3_1.verified.txt | 58 --- ...stemTextJson_i=None.DotNet6_0.verified.txt | 58 --- ...stemTextJson_i=None.DotNet7_0.verified.txt | 58 --- ...=SystemTextJson_i=None.Net4_8.verified.txt | 58 --- ...=TypeConverter_i=None.Core3_1.verified.txt | 82 ---- ...ypeConverter_i=None.DotNet6_0.verified.txt | 82 ---- ...ypeConverter_i=None.DotNet7_0.verified.txt | 82 ---- ...c=TypeConverter_i=None.Net4_8.verified.txt | 82 ---- ...ly_nestedClassCount=0.Core3_1.verified.txt | 56 --- ..._nestedClassCount=0.DotNet6_0.verified.txt | 56 --- ..._nestedClassCount=0.DotNet7_0.verified.txt | 56 --- ...tly_nestedClassCount=0.Net4_8.verified.txt | 56 --- ...ly_nestedClassCount=1.Core3_1.verified.txt | 59 --- ..._nestedClassCount=1.DotNet6_0.verified.txt | 59 --- ..._nestedClassCount=1.DotNet7_0.verified.txt | 59 --- ...tly_nestedClassCount=1.Net4_8.verified.txt | 59 --- ...ly_nestedClassCount=2.Core3_1.verified.txt | 62 --- ..._nestedClassCount=2.DotNet6_0.verified.txt | 62 --- ..._nestedClassCount=2.DotNet7_0.verified.txt | 62 --- ...tly_nestedClassCount=2.Net4_8.verified.txt | 62 --- ...ltIdInGlobalNamespace.Core3_1.verified.txt | 333 ------------- ...IdInGlobalNamespace.DotNet6_0.verified.txt | 333 ------------- ...IdInGlobalNamespace.DotNet7_0.verified.txt | 333 ------------- ...ultIdInGlobalNamespace.Net4_8.verified.txt | 333 ------------- ...ateDefaultIdInGlobalNamespace.verified.txt | 4 +- ...InFileScopedNamespace.Core3_1.verified.txt | 336 ------------- ...FileScopedNamespace.DotNet6_0.verified.txt | 336 ------------- ...FileScopedNamespace.DotNet7_0.verified.txt | 336 ------------- ...dInFileScopedNamespace.Net4_8.verified.txt | 336 ------------- ...nerateIdInFileScopedNamespace.verified.txt | 4 +- ...GenerateIdInNamespace.Core3_1.verified.txt | 336 ------------- ...nerateIdInNamespace.DotNet6_0.verified.txt | 336 ------------- ...nerateIdInNamespace.DotNet7_0.verified.txt | 336 ------------- ...nGenerateIdInNamespace.Net4_8.verified.txt | 336 ------------- ...ests.CanGenerateIdInNamespace.verified.txt | 4 +- ...tJson, SystemTextJson.Core3_1.verified.txt | 308 ------------ ...son, SystemTextJson.DotNet6_0.verified.txt | 308 ------------ ...son, SystemTextJson.DotNet7_0.verified.txt | 308 ------------ ...ftJson, SystemTextJson.Net4_8.verified.txt | 308 ------------ ...ewtonsoftJson, SystemTextJson.verified.txt | 4 +- ...verter=NewtonsoftJson.Core3_1.verified.txt | 294 ------------ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 294 ------------ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 294 ------------ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 294 ------------ ...Guid_converter=NewtonsoftJson.verified.txt | 4 +- ...verter=SystemTextJson.Core3_1.verified.txt | 287 ------------ ...rter=SystemTextJson.DotNet6_0.verified.txt | 287 ------------ ...rter=SystemTextJson.DotNet7_0.verified.txt | 287 ------------ ...nverter=SystemTextJson.Net4_8.verified.txt | 287 ------------ ...Guid_converter=SystemTextJson.verified.txt | 4 +- ...nverter=TypeConverter.Core3_1.verified.txt | 315 ------------- ...erter=TypeConverter.DotNet6_0.verified.txt | 315 ------------- ...erter=TypeConverter.DotNet7_0.verified.txt | 315 ------------- ...onverter=TypeConverter.Net4_8.verified.txt | 315 ------------- ...=Guid_converter=TypeConverter.verified.txt | 4 +- ...e=Guid_converter=null.Core3_1.verified.txt | 336 ------------- ...Guid_converter=null.DotNet6_0.verified.txt | 336 ------------- ...Guid_converter=null.DotNet7_0.verified.txt | 336 ------------- ...pe=Guid_converter=null.Net4_8.verified.txt | 336 ------------- ...ckingType=Guid_converter=null.verified.txt | 4 +- ...tJson, SystemTextJson.Core3_1.verified.txt | 308 ------------ ...son, SystemTextJson.DotNet6_0.verified.txt | 308 ------------ ...son, SystemTextJson.DotNet7_0.verified.txt | 308 ------------ ...ftJson, SystemTextJson.Net4_8.verified.txt | 308 ------------ ...ewtonsoftJson, SystemTextJson.verified.txt | 4 +- ...verter=NewtonsoftJson.Core3_1.verified.txt | 294 ------------ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 294 ------------ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 294 ------------ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 294 ------------ ...Guid_converter=NewtonsoftJson.verified.txt | 4 +- ...verter=SystemTextJson.Core3_1.verified.txt | 287 ------------ ...rter=SystemTextJson.DotNet6_0.verified.txt | 287 ------------ ...rter=SystemTextJson.DotNet7_0.verified.txt | 287 ------------ ...nverter=SystemTextJson.Net4_8.verified.txt | 287 ------------ ...Guid_converter=SystemTextJson.verified.txt | 4 +- ...nverter=TypeConverter.Core3_1.verified.txt | 315 ------------- ...erter=TypeConverter.DotNet6_0.verified.txt | 315 ------------- ...erter=TypeConverter.DotNet7_0.verified.txt | 315 ------------- ...onverter=TypeConverter.Net4_8.verified.txt | 315 ------------- ...=Guid_converter=TypeConverter.verified.txt | 4 +- ...e=Guid_converter=null.Core3_1.verified.txt | 336 ------------- ...Guid_converter=null.DotNet6_0.verified.txt | 336 ------------- ...Guid_converter=null.DotNet7_0.verified.txt | 336 ------------- ...pe=Guid_converter=null.Net4_8.verified.txt | 336 ------------- ...ckingType=Guid_converter=null.verified.txt | 4 +- ...ltipleIdsWithSameName.Core3_1.verified.txt | 440 ------------------ ...ipleIdsWithSameName.DotNet6_0.verified.txt | 440 ------------------ ...ipleIdsWithSameName.DotNet7_0.verified.txt | 440 ------------------ ...ultipleIdsWithSameName.Net4_8.verified.txt | 440 ------------------ ...nerateMultipleIdsWithSameName.verified.txt | 4 +- ...dInFileScopeNamespace.Core3_1.verified.txt | 339 -------------- ...nFileScopeNamespace.DotNet6_0.verified.txt | 339 -------------- ...nFileScopeNamespace.DotNet7_0.verified.txt | 339 -------------- ...IdInFileScopeNamespace.Net4_8.verified.txt | 339 -------------- ...eNestedIdInFileScopeNamespace.verified.txt | 4 +- ...dInFileScopeNamespace.Core3_1.verified.txt | 345 -------------- ...nFileScopeNamespace.DotNet6_0.verified.txt | 345 -------------- ...nFileScopeNamespace.DotNet7_0.verified.txt | 345 -------------- ...IdInFileScopeNamespace.Net4_8.verified.txt | 345 -------------- ...yNestedIdInFileScopeNamespace.verified.txt | 4 +- ...sUsingGlobalAttribute.Core3_1.verified.txt | 269 ----------- ...singGlobalAttribute.DotNet6_0.verified.txt | 269 ----------- ...singGlobalAttribute.DotNet7_0.verified.txt | 269 ----------- ...tsUsingGlobalAttribute.Net4_8.verified.txt | 269 ----------- ...eDefaultsUsingGlobalAttribute.verified.txt | 4 +- .../StronglyTypedIds.Tests.csproj | 4 +- version.props | 2 +- 420 files changed, 51 insertions(+), 40862 deletions(-) delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt delete mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs index bb0a333a8..b323f597a 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs @@ -34,12 +34,10 @@ public enum StronglyTypedIdImplementations /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj index dfa2dcd98..5fd0485d3 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj @@ -1,7 +1,7 @@ - netstandard2.0;;net7.0 + netstandard2.0 enable StronglyTypedIds false diff --git a/src/StronglyTypedIds/StronglyTypedIds.csproj b/src/StronglyTypedIds/StronglyTypedIds.csproj index cdd8d2cc8..b3cd8e94d 100644 --- a/src/StronglyTypedIds/StronglyTypedIds.csproj +++ b/src/StronglyTypedIds/StronglyTypedIds.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net7.0 + netstandard2.0 false enable Tennisi.StronglyTypedId diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs index d205c674e..e9d354a67 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs @@ -1,10 +1,13 @@  public static TESTID Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new TESTID(Guid.Parse(s)); } public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(out res); + result = new TESTID(res); + return ok; } diff --git a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs index d205c674e..9369b51a6 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs @@ -1,10 +1,13 @@  public static TESTID Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new TESTID(int.Parse(s)); } public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + int res = 0; + var ok = int.TryParse(out res); + result = new TESTID(res); + return ok; } diff --git a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs index d205c674e..0b8f613e8 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs @@ -1,10 +1,13 @@  public static TESTID Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new TESTID(long.Parse(s)); } public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + long res = 0; + var ok = long.TryParse(out res); + result = new TESTID(res); + return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt deleted file mode 100644 index 58a2c4794..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt deleted file mode 100644 index 58a2c4794..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt deleted file mode 100644 index 58a2c4794..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt deleted file mode 100644 index 58a2c4794..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt deleted file mode 100644 index 4ea1be319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt deleted file mode 100644 index 4ea1be319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt deleted file mode 100644 index 4ea1be319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt deleted file mode 100644 index 4ea1be319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt deleted file mode 100644 index f9fffe68a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt deleted file mode 100644 index f9fffe68a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt deleted file mode 100644 index f9fffe68a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt deleted file mode 100644 index f9fffe68a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt deleted file mode 100644 index 3df9e2e31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt deleted file mode 100644 index 3df9e2e31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt deleted file mode 100644 index 3df9e2e31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt deleted file mode 100644 index 3df9e2e31..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt deleted file mode 100644 index fec04c8e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt deleted file mode 100644 index fec04c8e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt deleted file mode 100644 index fec04c8e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt deleted file mode 100644 index fec04c8e1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt index fec04c8e1..3eb5342b4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt @@ -47,13 +47,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 806d124ae..7ee4bd7d4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt deleted file mode 100644 index 7ee4bd7d4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt deleted file mode 100644 index 806d124ae..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 95c5442ae..d65d51495 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt deleted file mode 100644 index d65d51495..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt deleted file mode 100644 index 95c5442ae..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ /dev/null @@ -1,157 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 3fa5fad11..09643c593 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt deleted file mode 100644 index 09643c593..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt deleted file mode 100644 index 3fa5fad11..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index 52fddbd6a..caa78ba07 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt deleted file mode 100644 index caa78ba07..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt deleted file mode 100644 index 52fddbd6a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ /dev/null @@ -1,165 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index 147d4c700..b45ca58f8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt deleted file mode 100644 index b45ca58f8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt deleted file mode 100644 index 147d4c700..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 2d01666a6..8612d81b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + readonly partial struct MyTestId : System.IComparable, System.IEquatable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt deleted file mode 100644 index 8612d81b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt deleted file mode 100644 index 2d01666a6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ /dev/null @@ -1,176 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index bb6b344ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 508208c37..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index db59f66c1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index bef90429e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index a13e9bec6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index 92cda7756..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index 92cda7756..fad5ea0b5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index fad5ea0b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index f72224715..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index d6d801a99..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 295e92baf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,78 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index f8d24bbf5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index d3e50467b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index b4d9738e7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index d76d3afd2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index 5d23b64a1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index e8afb0e98..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index e8afb0e98..45272d34a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index 45272d34a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index 297090ba1..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 7c016c3be..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt32()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 39f1e9331..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public int Value { get; } - - public MyTestId(int value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - int intValue => new MyTestId(intValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(int)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index 35fd482b5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index cb5754863..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 7052a3b27..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? new MyTestId(result.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index c38fa63f6..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index 13b9b1ac7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index 9b553ad33..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 9b553ad33..af1658c35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index af1658c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index 72b024dca..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 17a45333f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetInt64()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteNumberValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index e22d0478c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public long Value { get; } - - public MyTestId(long value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(0); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - long longValue => new MyTestId(longValue), - int intValue => new MyTestId(intValue), - short shortValue => new MyTestId(shortValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(long)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index 23efe4b09..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value.ToGuid(); - } - - public override MyTestId Parse(object value) - { - return value switch - { - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 9114f2d54..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value.ToGuid(), - value => new MyTestId(MassTransit.NewId.FromGuid(value)), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 181d85e44..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value.ToGuid()); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index 3a19fc65e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index b4c2d5867..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index 8898353da..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index 8898353da..7e4892f41 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index 7e4892f41..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index 699828755..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 3de0600ab..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value.ToGuid()); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 757eb4ebb..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public MassTransit.NewId Value { get; } - - public MyTestId(MassTransit.NewId value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); - public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || - sourceType == typeof(string) || base.CanConvertFrom - (context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - MassTransit.NewId newIdValue => new MyTestId(newIdValue), - System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(MassTransit.NewId)) - { - return idValue.Value; - } - - if (destinationType == typeof(System.Guid)) - { - return idValue.Value.ToGuid(); - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToGuid().ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index c96f1e168..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - null => new MyTestId(null), - System.DBNull => new MyTestId(null), - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index e1a174104..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) - : base( - id => id.Value!, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 9660c1fc0..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) - { - if (value is null) - { - serializer.Serialize(writer, null); - } - else - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index d779d1af4..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IComparable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index bb2e2c7d2..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IEquatable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index 8a440b779..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId : System.IParsable - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index 8a440b779..fe1e43665 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -10,7 +10,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index fe1e43665..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index c85338e9a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = true; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index c049fb7f5..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - if (value.Value is null) - { - writer.WriteNullValue(); - } - else - { - writer.WriteStringValue(value.Value); - } - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 50b3c0585..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -#nullable enable - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string? Value { get; } - - public MyTestId(string? value) - { - Value = value; - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value?.GetHashCode() ?? 0; - public override string? ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) - { - if (value is null) - { - return new MyTestId(null); - } - - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt deleted file mode 100644 index 749dd1dbd..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler - { - public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) - { - parameter.Value = value.Value; - } - - public override MyTestId Parse(object value) - { - return value switch - { - string stringValue => new MyTestId(stringValue), - _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), - }; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index 05700f78d..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - id => id.Value, - value => new MyTestId(value), - mappingHints - ) { } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt deleted file mode 100644 index d7596bf2b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyTestId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyTestId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (objectType == typeof(MyTestId?)) - { - var value = serializer.Deserialize(reader); - - return value is null ? null : new MyTestId(value); - } - - return new MyTestId(serializer.Deserialize(reader)); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt deleted file mode 100644 index 4fae5139a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IComparable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - public int CompareTo(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => 0, - (null, _) => -1, - (_, null) => 1, - (_, _) => Value.CompareTo(other.Value), - }; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt deleted file mode 100644 index 050bcc20b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IEquatable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.received.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt deleted file mode 100644 index 3ce01566b..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId : System.IParsable - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index 3ce01566b..0987c7d64 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId : System.IParsable + readonly partial struct MyTestId { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt deleted file mode 100644 index 0987c7d64..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt deleted file mode 100644 index 6e4590319..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter - { - public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) - { - var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; - schema.Type = idSchema.Type; - schema.Format = idSchema.Format; - schema.Example = idSchema.Example; - schema.Default = idSchema.Default; - schema.Properties = idSchema.Properties; - schema.Nullable = false; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt deleted file mode 100644 index 1396ccae3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(reader.GetString()); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt deleted file mode 100644 index d35ac20a3..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] - readonly partial struct MyTestId - { - public string Value { get; } - - public MyTestId(string value) - { - Value = value ?? throw new System.ArgumentNullException(nameof(value)); - } - - public static readonly MyTestId Empty = new MyTestId(string.Empty); - - public bool Equals(MyTestId other) - { - return (Value, other.Value) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - (_, _) => Value.Equals(other.Value), - }; - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value; - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - var stringValue = value as string; - if (stringValue is not null) - { - return new MyTestId(stringValue); - } - - return base.ConvertFrom(context, culture, value); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyTestId idValue) - { - if (destinationType == typeof(string)) - { - return idValue.Value; - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt deleted file mode 100644 index ff61cdde7..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt deleted file mode 100644 index dacf3158c..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt deleted file mode 100644 index b71458e7e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTestNamespace -{ - partial class OuterLayer1 - { - partial class OuterLayer0 - { - partial record InnerMost - { - [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] - readonly partial struct MyTestId - { - public System.Guid Value { get; } - - public MyTestId(System.Guid value) - { - Value = value; - } - - public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); - public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); - - public bool Equals(MyTestId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyTestId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); - public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - - class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyTestId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt deleted file mode 100644 index 12bc7a92a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt +++ /dev/null @@ -1,333 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt deleted file mode 100644 index 12bc7a92a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt +++ /dev/null @@ -1,333 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt deleted file mode 100644 index 12bc7a92a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt +++ /dev/null @@ -1,333 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt deleted file mode 100644 index 12bc7a92a..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt +++ /dev/null @@ -1,333 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 12bc7a92a..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 09e26fecf..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt deleted file mode 100644 index 09e26fecf..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 09e26fecf..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index bc83b2a93..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index a71f4a25e..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index da5f95855..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 9502b5987..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index d9c815c35..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt deleted file mode 100644 index bc83b2a93..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ /dev/null @@ -1,308 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index bc83b2a93..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt deleted file mode 100644 index a71f4a25e..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ /dev/null @@ -1,294 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index a71f4a25e..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt deleted file mode 100644 index da5f95855..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ /dev/null @@ -1,287 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter - { - public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) - { - return new MyId(System.Guid.Parse(reader.GetString())); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) - { - writer.WriteStringValue(value.Value); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index da5f95855..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt deleted file mode 100644 index 9502b5987..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ /dev/null @@ -1,315 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 9502b5987..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt deleted file mode 100644 index d9c815c35..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ /dev/null @@ -1,336 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyTests.TestNameSpace -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index d9c815c35..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt deleted file mode 100644 index ccf413db8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt +++ /dev/null @@ -1,440 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V1 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} - -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V2 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt deleted file mode 100644 index ccf413db8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt +++ /dev/null @@ -1,440 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V1 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} - -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V2 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt deleted file mode 100644 index ccf413db8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt +++ /dev/null @@ -1,440 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V1 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} - -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V2 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt deleted file mode 100644 index ccf413db8..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt +++ /dev/null @@ -1,440 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V1 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} - -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace MyContracts.V2 -{ - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index ccf413db8..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt deleted file mode 100644 index 3a5d8d449..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ /dev/null @@ -1,339 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt deleted file mode 100644 index 3a5d8d449..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ /dev/null @@ -1,339 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt deleted file mode 100644 index 3a5d8d449..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ /dev/null @@ -1,339 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt deleted file mode 100644 index 3a5d8d449..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ /dev/null @@ -1,339 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 3a5d8d449..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt deleted file mode 100644 index 96dfba11f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ /dev/null @@ -1,345 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass where T: new() - { - partial record InnerClass - { - partial struct InnerStruct - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt deleted file mode 100644 index 96dfba11f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ /dev/null @@ -1,345 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass where T: new() - { - partial record InnerClass - { - partial struct InnerStruct - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt deleted file mode 100644 index 96dfba11f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ /dev/null @@ -1,345 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass where T: new() - { - partial record InnerClass - { - partial struct InnerStruct - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt deleted file mode 100644 index 96dfba11f..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ /dev/null @@ -1,345 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - -namespace SomeNamespace -{ - partial class ParentClass where T: new() - { - partial record InnerClass - { - partial struct InnerStruct - { - [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] - [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public System.Guid Value { get; } - - public MyId(System.Guid value) - { - Value = value; - } - - public static MyId New() => new MyId(System.Guid.NewGuid()); - public static readonly MyId Empty = new MyId(System.Guid.Empty); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - class MyIdTypeConverter : System.ComponentModel.TypeConverter - { - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) - { - return value switch - { - System.Guid guidValue => new MyId(guidValue), - string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) - { - return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) - { - if (value is MyId idValue) - { - if (destinationType == typeof(System.Guid)) - { - return idValue.Value; - } - - if (destinationType == typeof(string)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(MyId); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (MyId)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var guid = serializer.Deserialize(reader); - return guid.HasValue ? new MyId(guid.Value) : null; - } - } - } - } - } - } -} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index 96dfba11f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt deleted file mode 100644 index 98786ec30..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt +++ /dev/null @@ -1,269 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyId(int value) - { - Value = value; - } - - public static readonly MyId Empty = new MyId(0); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt deleted file mode 100644 index 98786ec30..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt +++ /dev/null @@ -1,269 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyId(int value) - { - Value = value; - } - - public static readonly MyId Empty = new MyId(0); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt deleted file mode 100644 index 98786ec30..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt +++ /dev/null @@ -1,269 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyId(int value) - { - Value = value; - } - - public static readonly MyId Empty = new MyId(0); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt deleted file mode 100644 index 98786ec30..000000000 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt +++ /dev/null @@ -1,269 +0,0 @@ -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdAttribute : Attribute - { - /// - /// Make the struct a strongly typed ID - /// - /// The to use to store the strongly-typed ID value. - /// If not set, uses , which defaults to - /// Converters to create for serializing/deserializing the strongly-typed ID value. - /// If not set, uses , which defaults to - /// and - /// Interfaces and patterns the strongly typed id should implement - /// If not set, uses , which defaults to - /// and - public StronglyTypedIdAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The to use to store the strongly-typed ID value - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// JSON library used to serialize/deserialize strongly-typed ID value - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Used to control the default Place on partial structs to make the type a strongly-typed ID - /// - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] - internal sealed class StronglyTypedIdDefaultsAttribute : Attribute - { - /// - /// Set the default values used for strongly typed ids - /// - /// The to use to store the strongly-typed ID value. - /// Defaults to - /// JSON library used to serialize/deserialize strongly-typed ID value. - /// Defaults to and - /// Interfaces and patterns the strongly typed id should implement - /// Defaults to and - public StronglyTypedIdDefaultsAttribute( - StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, - StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, - StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) - { - BackingType = backingType; - Converters = converters; - Implementations = implementations; - } - - /// - /// The default to use to store the strongly-typed ID values. - /// - public StronglyTypedIdBackingType BackingType { get; } - - /// - /// The default converters to create for serializing/deserializing strongly-typed ID values. - /// - public StronglyTypedIdConverter Converters { get; } - - /// - /// Interfaces and patterns the strongly typed id should implement - /// - public StronglyTypedIdImplementations Implementations { get; } - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// The to use to store the value of a strongly-typed ID - /// - internal enum StronglyTypedIdBackingType - { - /// - /// Use the default backing type (either the globally configured default, or Guid) - /// - Default = 0, - - Guid = 1, - Int = 2, - String = 3, - Long = 4, - NullableString = 5, - MassTransitNewId = 6, - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Converters used to to serialize/deserialize strongly-typed ID values - /// - [Flags] - internal enum StronglyTypedIdConverter - { - // Used with HasFlag, so needs to be 1, 2, 4 etc - - /// - /// Don't create any converters for the strongly typed ID - /// - None = 0, - - /// - /// Use the default converters for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - /// - /// Creates a for converting from the strongly typed ID to and from a string - /// - TypeConverter = 2, - - /// - /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value - /// - NewtonsoftJson = 4, - - /// - /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value - /// - SystemTextJson = 8, - - /// - /// Creates an EF Core Value Converter for extracting the primitive value - /// - EfCoreValueConverter = 16, - - /// - /// Creates a Dapper TypeHandler for converting to and from the type - /// - DapperTypeHandler = 32, - - /// - /// Creates a Swagger SchemaFilter for OpenApi documentation - /// - SwaggerSchemaFilter = 64, - - } -} -#endif -#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES - -using System; - -namespace StronglyTypedIds -{ - /// - /// Interfaces and patterns the strongly typed id should implement - /// - [Flags] - internal enum StronglyTypedIdImplementations - { - // Used with HasFlag, so needs to be 1, 2, 4, 8 etc - - /// - /// Don't implement any additional members for the strongly typed ID - /// - None = 0, - - /// - /// Use the default implementations for the strongly typed Id. - /// This will be the value provided in the , which falls back to - /// and - /// - Default = 1, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IEquatable = 2, - - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IComparable = 4, - - #if NET7_0_OR_GREATER - // ReSharper disable once InconsistentNaming - /// - /// Implement the interface - /// - IParsable = 8, - #endif - } -} - -#endif -//------------------------------------------------------------------------------ -// -// This code was generated by the StronglyTypedId source generator -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#pragma warning disable 1591 // publicly visible type or member must be documented - - readonly partial struct MyId : System.IComparable, System.IEquatable - { - public int Value { get; } - - public MyId(int value) - { - Value = value; - } - - public static readonly MyId Empty = new MyId(0); - - public bool Equals(MyId other) => this.Value.Equals(other.Value); - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is MyId other && Equals(other); - } - - public override int GetHashCode() => Value.GetHashCode(); - - public override string ToString() => Value.ToString(); - public static bool operator ==(MyId a, MyId b) => a.Equals(b); - public static bool operator !=(MyId a, MyId b) => !(a == b); - public int CompareTo(MyId other) => Value.CompareTo(other.Value); - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index 98786ec30..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -220,13 +220,11 @@ namespace StronglyTypedIds /// IComparable = 4, - #if NET7_0_OR_GREATER // ReSharper disable once InconsistentNaming /// /// Implement the interface /// - IParsable = 8, - #endif + IParsable = 8 } } diff --git a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj index 4fc7f0fb2..f9f9f8a59 100644 --- a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj +++ b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj @@ -1,8 +1,8 @@  - netcoreapp3.1;net6.0;net7.0 - net48;$(TargetFrameworks) + net7.0 + net7.0 false latest diff --git a/version.props b/version.props index 44d14f703..d2d74dc06 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.4 + 1.0.5 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From b9177146a2777a6f94d0e6387869677aa5dbe68a Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 02:59:45 +0300 Subject: [PATCH 24/37] iparsable test --- .../SourceGenerationHelper.cs | 7 - ...ly_type=Guid.DotNet7_0.DotNet.verified.txt | 157 +++++++++++++++ ...atesFullIdCorrectly_type=Guid.verified.txt | 157 +++++++++++++++ ...tly_type=Int.DotNet7_0.DotNet.verified.txt | 157 +++++++++++++++ ...ratesFullIdCorrectly_type=Int.verified.txt | 157 +++++++++++++++ ...ly_type=Long.DotNet7_0.DotNet.verified.txt | 160 +++++++++++++++ ...atesFullIdCorrectly_type=Long.verified.txt | 160 +++++++++++++++ ...TransitNewId.DotNet7_0.DotNet.verified.txt | 165 +++++++++++++++ ...rrectly_type=MassTransitNewId.verified.txt | 165 +++++++++++++++ ...llableString.DotNet7_0.DotNet.verified.txt | 190 ++++++++++++++++++ ...Correctly_type=NullableString.verified.txt | 190 ++++++++++++++++++ ..._type=String.DotNet7_0.DotNet.verified.txt | 176 ++++++++++++++++ ...esFullIdCorrectly_type=String.verified.txt | 176 ++++++++++++++++ ..._type=Guid_c=None_i=IParsable.verified.txt | 2 +- ...y_type=Int_c=None_i=IParsable.verified.txt | 2 +- ..._type=Long_c=None_i=IParsable.verified.txt | 2 +- ...ansitNewId_c=None_i=IParsable.verified.txt | 2 +- ...ableString_c=None_i=IParsable.verified.txt | 2 +- ...ype=String_c=None_i=IParsable.verified.txt | 2 +- version.props | 2 +- 20 files changed, 2017 insertions(+), 14 deletions(-) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index aa392441a..0a59dc895 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -73,10 +73,7 @@ static string CreateId( var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable); var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable); - - #if NET7_0_OR_GREATER var useParsable = implementations.IsSet(StronglyTypedIdImplementations.IParsable); - #endif var parentsCount = 0; @@ -134,11 +131,7 @@ static string CreateId( sb.Append(resources.BaseId); - #if NET7_0_OR_GREATER ReplaceInterfaces(sb, useIEquatable, useIComparable, useParsable); - #else - ReplaceInterfaces(sb, useIEquatable, useIComparable, false); - #endif // IEquatable is already implemented whether or not the interface is implemented diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..7ee4bd7d4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..d65d51495 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..09643c593 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt new file mode 100644 index 000000000..3fa5fad11 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -0,0 +1,160 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..caa78ba07 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..b45ca58f8 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt new file mode 100644 index 000000000..8612d81b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index fad5ea0b5..92cda7756 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index 45272d34a..e8afb0e98 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index af1658c35..9b553ad33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public long Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index 7e4892f41..8898353da 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index fe1e43665..8a440b779 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -10,7 +10,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented #nullable enable - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index 0987c7d64..3ce01566b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -9,7 +9,7 @@ #pragma warning disable 1591 // publicly visible type or member must be documented - readonly partial struct MyTestId + readonly partial struct MyTestId : System.IParsable { public string Value { get; } diff --git a/version.props b/version.props index d2d74dc06..4c6fb8e0d 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.5 + 1.0.6 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 7a34b7fe020a66a03fb4c99fa4aaffbbd1c4e5e5 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:04:51 +0300 Subject: [PATCH 25/37] nullables disable --- .../StronglyTypedIds.Attributes.csproj | 2 +- src/StronglyTypedIds/StronglyTypedIds.csproj | 2 +- .../StronglyTypedIds.IntegrationTests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj index 5fd0485d3..e59e85434 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj @@ -2,7 +2,7 @@ netstandard2.0 - enable + disable StronglyTypedIds false diff --git a/src/StronglyTypedIds/StronglyTypedIds.csproj b/src/StronglyTypedIds/StronglyTypedIds.csproj index b3cd8e94d..7e19f9fb4 100644 --- a/src/StronglyTypedIds/StronglyTypedIds.csproj +++ b/src/StronglyTypedIds/StronglyTypedIds.csproj @@ -3,7 +3,7 @@ netstandard2.0 false - enable + disable Tennisi.StronglyTypedId A source generator for creating strongly-typed IDs by decorating with a [StronglyTypedId] attribute diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 8909346e3..6c9961413 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -4,7 +4,7 @@ netcoreapp3.1;net6.0;net7.0 net48;$(TargetFrameworks) false - enable + disable true From 0afb021860580b029c31bd31d48452a4f0f276ea Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:05:29 +0300 Subject: [PATCH 26/37] nullables disable --- version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.props b/version.props index 4c6fb8e0d..217277c96 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.6 + 1.0.7 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From ff7a8d0644cdadd510425a9d0700ec712b0f4339 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:10:12 +0300 Subject: [PATCH 27/37] all frameworks --- test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj index f9f9f8a59..4fc7f0fb2 100644 --- a/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj +++ b/test/StronglyTypedIds.Tests/StronglyTypedIds.Tests.csproj @@ -1,8 +1,8 @@  - net7.0 - net7.0 + netcoreapp3.1;net6.0;net7.0 + net48;$(TargetFrameworks) false latest From d2d4d74a8335c7adcf0b14e92ef7671f7b0f5bef Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:11:41 +0300 Subject: [PATCH 28/37] decimal for DapperHandler --- src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs | 3 ++- version.props | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs index 42dac85c9..5977e1d8b 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs @@ -12,9 +12,10 @@ public override TESTID Parse(object value) { long longValue => new TESTID(longValue), int intValue => new TESTID(intValue), + decimal decimalValue = new TESTID(decimalValue), short shortValue => new TESTID(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new TESTID(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + } diff --git a/version.props b/version.props index 217277c96..95d01dc81 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.7 + 1.0.8 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From b0864525e831f35b5f7da9f278a0be452d03f7aa Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:15:43 +0300 Subject: [PATCH 29/37] dapper decimal --- src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs index 5977e1d8b..bfa6041dd 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs @@ -12,7 +12,7 @@ public override TESTID Parse(object value) { long longValue => new TESTID(longValue), int intValue => new TESTID(intValue), - decimal decimalValue = new TESTID(decimalValue), + decimal decimalValue => new TESTID(decimalValue), short shortValue => new TESTID(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new TESTID(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), From 37de46408031f957ebc89eedfc1a0f74d5f4213f Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:40:39 +0300 Subject: [PATCH 30/37] decimal value (long) --- src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs | 2 +- version.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs index bfa6041dd..eb6441ac7 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs @@ -12,7 +12,7 @@ public override TESTID Parse(object value) { long longValue => new TESTID(longValue), int intValue => new TESTID(intValue), - decimal decimalValue => new TESTID(decimalValue), + decimal decimalValue => new TESTID((long)decimalValue), short shortValue => new TESTID(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new TESTID(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), diff --git a/version.props b/version.props index 95d01dc81..eb9229570 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.8 + 1.0.10 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 2f6969e5b9a1c479ffa2d23aa3032f229632a1ae Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 03:56:34 +0300 Subject: [PATCH 31/37] parsable test --- .../StronglyTypedIds.Attributes.csproj | 2 +- src/StronglyTypedIds/StronglyTypedIds.csproj | 2 +- ...onglyTypedIdAttribute.Core3_1.verified.txt | 62 +++ ...glyTypedIdAttribute.DotNet6_0.verified.txt | 62 +++ ...glyTypedIdAttribute.DotNet7_0.verified.txt | 62 +++ ...ronglyTypedIdAttribute.Net4_8.verified.txt | 62 +++ ...glyTypedIdBackingType.Core3_1.verified.txt | 36 ++ ...yTypedIdBackingType.DotNet6_0.verified.txt | 36 ++ ...yTypedIdBackingType.DotNet7_0.verified.txt | 36 ++ ...nglyTypedIdBackingType.Net4_8.verified.txt | 36 ++ ...onglyTypedIdConverter.Core3_1.verified.txt | 70 +++ ...glyTypedIdConverter.DotNet6_0.verified.txt | 70 +++ ...glyTypedIdConverter.DotNet7_0.verified.txt | 70 +++ ...ronglyTypedIdConverter.Net4_8.verified.txt | 70 +++ ...edIdDefaultsAttribute.Core3_1.verified.txt | 60 +++ ...IdDefaultsAttribute.DotNet6_0.verified.txt | 60 +++ ...IdDefaultsAttribute.DotNet7_0.verified.txt | 60 +++ ...pedIdDefaultsAttribute.Net4_8.verified.txt | 60 +++ ...ypedIdImplementations.Core3_1.verified.txt | 58 +++ ...edIdImplementations.DotNet6_0.verified.txt | 58 +++ ...edIdImplementations.DotNet7_0.verified.txt | 58 +++ ...TypedIdImplementations.Net4_8.verified.txt | 58 +++ ...dCorrectly_type=Guid.Core3_1.verified.txt} | 2 +- ...Correctly_type=Guid.DotNet6_0.verified.txt | 157 +++++++ ...Correctly_type=Guid.DotNet7_0.verified.txt | 2 +- ...lIdCorrectly_type=Guid.Net4_8.verified.txt | 157 +++++++ ...IdCorrectly_type=Int.Core3_1.verified.txt} | 2 +- ...dCorrectly_type=Int.DotNet6_0.verified.txt | 157 +++++++ ...dCorrectly_type=Int.DotNet7_0.verified.txt | 2 +- ...llIdCorrectly_type=Int.Net4_8.verified.txt | 157 +++++++ ...dCorrectly_type=Long.Core3_1.verified.txt} | 4 +- ...Correctly_type=Long.DotNet6_0.verified.txt | 162 +++++++ ...Correctly_type=Long.DotNet7_0.verified.txt | 4 +- ...lIdCorrectly_type=Long.Net4_8.verified.txt | 162 +++++++ ...atesFullIdCorrectly_type=Long.verified.txt | 2 + ...ype=MassTransitNewId.Core3_1.verified.txt} | 2 +- ...pe=MassTransitNewId.DotNet6_0.verified.txt | 165 +++++++ ...pe=MassTransitNewId.DotNet7_0.verified.txt | 2 +- ..._type=MassTransitNewId.Net4_8.verified.txt | 165 +++++++ ..._type=NullableString.Core3_1.verified.txt} | 2 +- ...type=NullableString.DotNet6_0.verified.txt | 190 ++++++++ ...type=NullableString.DotNet7_0.verified.txt | 2 +- ...ly_type=NullableString.Net4_8.verified.txt | 190 ++++++++ ...orrectly_type=String.Core3_1.verified.txt} | 2 +- ...rrectly_type=String.DotNet6_0.verified.txt | 176 +++++++ ...rrectly_type=String.DotNet7_0.verified.txt | 2 +- ...dCorrectly_type=String.Net4_8.verified.txt | 176 +++++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++ ...ValueConverter_i=None.Core3_1.verified.txt | 47 ++ ...lueConverter_i=None.DotNet6_0.verified.txt | 47 ++ ...lueConverter_i=None.DotNet7_0.verified.txt | 47 ++ ...eValueConverter_i=None.Net4_8.verified.txt | 47 ++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 37 ++ ...=None_i=IComparable.DotNet6_0.verified.txt | 37 ++ ...=None_i=IComparable.DotNet7_0.verified.txt | 37 ++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 ++ ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 ++ ...id_c=None_i=IEquatable.Net4_8.verified.txt | 36 ++ ...id_c=None_i=IParsable.Core3_1.verified.txt | 36 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 ++ ...uid_c=None_i=IParsable.Net4_8.verified.txt | 36 ++ ...pe=Guid_c=None_i=None.Core3_1.verified.txt | 36 ++ ...=Guid_c=None_i=None.DotNet6_0.verified.txt | 36 ++ ...=Guid_c=None_i=None.DotNet7_0.verified.txt | 36 ++ ...ype=Guid_c=None_i=None.Net4_8.verified.txt | 36 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 ++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 ++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 ++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 ++ ...SystemTextJson_i=None.Core3_1.verified.txt | 50 ++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 ++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 ++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 ++ ...=TypeConverter_i=None.Core3_1.verified.txt | 78 ++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 78 ++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 78 ++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 78 ++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++ ...ValueConverter_i=None.Core3_1.verified.txt | 46 ++ ...lueConverter_i=None.DotNet6_0.verified.txt | 46 ++ ...lueConverter_i=None.DotNet7_0.verified.txt | 46 ++ ...eValueConverter_i=None.Net4_8.verified.txt | 46 ++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 36 ++ ...=None_i=IComparable.DotNet6_0.verified.txt | 36 ++ ...=None_i=IComparable.DotNet7_0.verified.txt | 36 ++ ...t_c=None_i=IComparable.Net4_8.verified.txt | 36 ++ ...t_c=None_i=IEquatable.Core3_1.verified.txt | 35 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 ++ ...nt_c=None_i=IEquatable.Net4_8.verified.txt | 35 ++ ...nt_c=None_i=IParsable.Core3_1.verified.txt | 35 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 ++ ...Int_c=None_i=IParsable.Net4_8.verified.txt | 35 ++ ...ype=Int_c=None_i=None.Core3_1.verified.txt | 35 ++ ...e=Int_c=None_i=None.DotNet6_0.verified.txt | 35 ++ ...e=Int_c=None_i=None.DotNet7_0.verified.txt | 35 ++ ...type=Int_c=None_i=None.Net4_8.verified.txt | 35 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 ++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 ++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 ++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 ++ ...SystemTextJson_i=None.Core3_1.verified.txt | 49 ++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 ++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 ++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 ++ ...=TypeConverter_i=None.Core3_1.verified.txt | 77 +++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 77 +++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 77 +++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 77 +++ ...perTypeHandler_i=None.Core3_1.verified.txt | 57 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 57 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 57 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 57 +++ ...ng_c=DapperTypeHandler_i=None.verified.txt | 2 + ...ValueConverter_i=None.Core3_1.verified.txt | 46 ++ ...lueConverter_i=None.DotNet6_0.verified.txt | 46 ++ ...lueConverter_i=None.DotNet7_0.verified.txt | 46 ++ ...eValueConverter_i=None.Net4_8.verified.txt | 46 ++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 56 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 56 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 56 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 56 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 36 ++ ...=None_i=IComparable.DotNet6_0.verified.txt | 36 ++ ...=None_i=IComparable.DotNet7_0.verified.txt | 36 ++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 36 ++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 35 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 35 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 35 ++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 35 ++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 35 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 35 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 35 ++ ...ong_c=None_i=IParsable.Net4_8.verified.txt | 35 ++ ...pe=Long_c=None_i=None.Core3_1.verified.txt | 35 ++ ...=Long_c=None_i=None.DotNet6_0.verified.txt | 35 ++ ...=Long_c=None_i=None.DotNet7_0.verified.txt | 35 ++ ...ype=Long_c=None_i=None.Net4_8.verified.txt | 35 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 49 ++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 49 ++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 49 ++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 49 ++ ...SystemTextJson_i=None.Core3_1.verified.txt | 49 ++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 49 ++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 49 ++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 49 ++ ...=TypeConverter_i=None.Core3_1.verified.txt | 79 ++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 79 ++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 79 ++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 79 ++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 54 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 54 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 54 +++ ...ValueConverter_i=None.Core3_1.verified.txt | 47 ++ ...lueConverter_i=None.DotNet6_0.verified.txt | 47 ++ ...lueConverter_i=None.DotNet7_0.verified.txt | 47 ++ ...eValueConverter_i=None.Net4_8.verified.txt | 47 ++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 57 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 57 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 57 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 57 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 37 ++ ...=None_i=IComparable.DotNet6_0.verified.txt | 37 ++ ...=None_i=IComparable.DotNet7_0.verified.txt | 37 ++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 37 ++ ...d_c=None_i=IEquatable.Core3_1.verified.txt | 36 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 36 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 36 ++ ...Id_c=None_i=IEquatable.Net4_8.verified.txt | 36 ++ ...Id_c=None_i=IParsable.Core3_1.verified.txt | 36 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 36 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 36 ++ ...wId_c=None_i=IParsable.Net4_8.verified.txt | 36 ++ ...itNewId_c=None_i=None.Core3_1.verified.txt | 36 ++ ...NewId_c=None_i=None.DotNet6_0.verified.txt | 36 ++ ...NewId_c=None_i=None.DotNet7_0.verified.txt | 36 ++ ...sitNewId_c=None_i=None.Net4_8.verified.txt | 36 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 50 ++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 50 ++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 50 ++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 50 ++ ...SystemTextJson_i=None.Core3_1.verified.txt | 50 ++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 50 ++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 50 ++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 50 ++ ...=TypeConverter_i=None.Core3_1.verified.txt | 86 ++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 86 ++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 86 ++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 86 ++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 63 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 63 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 63 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 63 +++ ...ValueConverter_i=None.Core3_1.verified.txt | 55 +++ ...lueConverter_i=None.DotNet6_0.verified.txt | 55 +++ ...lueConverter_i=None.DotNet7_0.verified.txt | 55 +++ ...eValueConverter_i=None.Net4_8.verified.txt | 55 +++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 54 +++ ...=None_i=IComparable.DotNet6_0.verified.txt | 54 +++ ...=None_i=IComparable.DotNet7_0.verified.txt | 54 +++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 +++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 ++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 ++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 ++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 ++ ...eString_c=None_i=None.Core3_1.verified.txt | 44 ++ ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 ++ ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 ++ ...leString_c=None_i=None.Net4_8.verified.txt | 44 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 +++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 +++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 +++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 +++ ...SystemTextJson_i=None.Core3_1.verified.txt | 65 +++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 65 +++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 65 +++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 65 +++ ...=TypeConverter_i=None.Core3_1.verified.txt | 87 ++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 87 ++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 87 ++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 87 ++++ ...perTypeHandler_i=None.Core3_1.verified.txt | 61 +++ ...rTypeHandler_i=None.DotNet6_0.verified.txt | 61 +++ ...rTypeHandler_i=None.DotNet7_0.verified.txt | 61 +++ ...pperTypeHandler_i=None.Net4_8.verified.txt | 61 +++ ...ValueConverter_i=None.Core3_1.verified.txt | 55 +++ ...lueConverter_i=None.DotNet6_0.verified.txt | 55 +++ ...lueConverter_i=None.DotNet7_0.verified.txt | 55 +++ ...eValueConverter_i=None.Net4_8.verified.txt | 55 +++ ...NewtonsoftJson_i=None.Core3_1.verified.txt | 71 +++ ...wtonsoftJson_i=None.DotNet6_0.verified.txt | 71 +++ ...wtonsoftJson_i=None.DotNet7_0.verified.txt | 71 +++ ...=NewtonsoftJson_i=None.Net4_8.verified.txt | 71 +++ ..._c=None_i=IComparable.Core3_1.verified.txt | 54 +++ ...=None_i=IComparable.DotNet6_0.verified.txt | 54 +++ ...=None_i=IComparable.DotNet7_0.verified.txt | 54 +++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 54 +++ ...g_c=None_i=IEquatable.Core3_1.verified.txt | 44 ++ ...c=None_i=IEquatable.DotNet6_0.verified.txt | 44 ++ ...c=None_i=IEquatable.DotNet7_0.verified.txt | 44 ++ ...ng_c=None_i=IEquatable.Net4_8.verified.txt | 44 ++ ...ng_c=None_i=IParsable.Core3_1.verified.txt | 44 ++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 44 ++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 44 ++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 44 ++ ...=String_c=None_i=None.Core3_1.verified.txt | 44 ++ ...tring_c=None_i=None.DotNet6_0.verified.txt | 44 ++ ...tring_c=None_i=None.DotNet7_0.verified.txt | 44 ++ ...e=String_c=None_i=None.Net4_8.verified.txt | 44 ++ ...erSchemaFilter_i=None.Core3_1.verified.txt | 59 +++ ...SchemaFilter_i=None.DotNet6_0.verified.txt | 59 +++ ...SchemaFilter_i=None.DotNet7_0.verified.txt | 59 +++ ...gerSchemaFilter_i=None.Net4_8.verified.txt | 59 +++ ...SystemTextJson_i=None.Core3_1.verified.txt | 58 +++ ...stemTextJson_i=None.DotNet6_0.verified.txt | 58 +++ ...stemTextJson_i=None.DotNet7_0.verified.txt | 58 +++ ...=SystemTextJson_i=None.Net4_8.verified.txt | 58 +++ ...=TypeConverter_i=None.Core3_1.verified.txt | 82 ++++ ...ypeConverter_i=None.DotNet6_0.verified.txt | 82 ++++ ...ypeConverter_i=None.DotNet7_0.verified.txt | 82 ++++ ...c=TypeConverter_i=None.Net4_8.verified.txt | 82 ++++ ...ly_nestedClassCount=0.Core3_1.verified.txt | 56 +++ ..._nestedClassCount=0.DotNet6_0.verified.txt | 56 +++ ..._nestedClassCount=0.DotNet7_0.verified.txt | 56 +++ ...tly_nestedClassCount=0.Net4_8.verified.txt | 56 +++ ...ly_nestedClassCount=1.Core3_1.verified.txt | 59 +++ ..._nestedClassCount=1.DotNet6_0.verified.txt | 59 +++ ..._nestedClassCount=1.DotNet7_0.verified.txt | 59 +++ ...tly_nestedClassCount=1.Net4_8.verified.txt | 59 +++ ...ly_nestedClassCount=2.Core3_1.verified.txt | 62 +++ ..._nestedClassCount=2.DotNet6_0.verified.txt | 62 +++ ..._nestedClassCount=2.DotNet7_0.verified.txt | 62 +++ ...tly_nestedClassCount=2.Net4_8.verified.txt | 62 +++ ...ltIdInGlobalNamespace.Core3_1.verified.txt | 331 +++++++++++++ ...IdInGlobalNamespace.DotNet6_0.verified.txt | 331 +++++++++++++ ...IdInGlobalNamespace.DotNet7_0.verified.txt | 331 +++++++++++++ ...ultIdInGlobalNamespace.Net4_8.verified.txt | 331 +++++++++++++ ...InFileScopedNamespace.Core3_1.verified.txt | 334 +++++++++++++ ...FileScopedNamespace.DotNet6_0.verified.txt | 334 +++++++++++++ ...FileScopedNamespace.DotNet7_0.verified.txt | 334 +++++++++++++ ...dInFileScopedNamespace.Net4_8.verified.txt | 334 +++++++++++++ ...GenerateIdInNamespace.Core3_1.verified.txt | 334 +++++++++++++ ...nerateIdInNamespace.DotNet6_0.verified.txt | 334 +++++++++++++ ...nerateIdInNamespace.DotNet7_0.verified.txt | 334 +++++++++++++ ...nGenerateIdInNamespace.Net4_8.verified.txt | 334 +++++++++++++ ...tJson, SystemTextJson.Core3_1.verified.txt | 306 ++++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 306 ++++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 306 ++++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 306 ++++++++++++ ...verter=NewtonsoftJson.Core3_1.verified.txt | 292 ++++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 292 ++++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 292 ++++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 292 ++++++++++++ ...verter=SystemTextJson.Core3_1.verified.txt | 285 ++++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 285 ++++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 285 ++++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 285 ++++++++++++ ...nverter=TypeConverter.Core3_1.verified.txt | 313 +++++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 313 +++++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 313 +++++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 313 +++++++++++++ ...e=Guid_converter=null.Core3_1.verified.txt | 334 +++++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 334 +++++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 334 +++++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 334 +++++++++++++ ...tJson, SystemTextJson.Core3_1.verified.txt | 306 ++++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 306 ++++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 306 ++++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 306 ++++++++++++ ...verter=NewtonsoftJson.Core3_1.verified.txt | 292 ++++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 292 ++++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 292 ++++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 292 ++++++++++++ ...verter=SystemTextJson.Core3_1.verified.txt | 285 ++++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 285 ++++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 285 ++++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 285 ++++++++++++ ...nverter=TypeConverter.Core3_1.verified.txt | 313 +++++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 313 +++++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 313 +++++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 313 +++++++++++++ ...e=Guid_converter=null.Core3_1.verified.txt | 334 +++++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 334 +++++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 334 +++++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 334 +++++++++++++ ...ltipleIdsWithSameName.Core3_1.verified.txt | 438 ++++++++++++++++++ ...ipleIdsWithSameName.DotNet6_0.verified.txt | 438 ++++++++++++++++++ ...ipleIdsWithSameName.DotNet7_0.verified.txt | 438 ++++++++++++++++++ ...ultipleIdsWithSameName.Net4_8.verified.txt | 438 ++++++++++++++++++ ...dInFileScopeNamespace.Core3_1.verified.txt | 337 ++++++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 337 ++++++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 337 ++++++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 337 ++++++++++++++ ...dInFileScopeNamespace.Core3_1.verified.txt | 343 ++++++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 343 ++++++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 343 ++++++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 343 ++++++++++++++ ...sUsingGlobalAttribute.Core3_1.verified.txt | 267 +++++++++++ ...singGlobalAttribute.DotNet6_0.verified.txt | 267 +++++++++++ ...singGlobalAttribute.DotNet7_0.verified.txt | 267 +++++++++++ ...tsUsingGlobalAttribute.Net4_8.verified.txt | 267 +++++++++++ version.props | 2 +- 369 files changed, 37973 insertions(+), 15 deletions(-) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt} (99%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt} (99%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt} (98%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt} (99%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt} (99%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt rename test/StronglyTypedIds.Tests/Snapshots/{SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt => SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt} (99%) create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt create mode 100644 test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj index e59e85434..5fd0485d3 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj @@ -2,7 +2,7 @@ netstandard2.0 - disable + enable StronglyTypedIds false diff --git a/src/StronglyTypedIds/StronglyTypedIds.csproj b/src/StronglyTypedIds/StronglyTypedIds.csproj index 7e19f9fb4..b3cd8e94d 100644 --- a/src/StronglyTypedIds/StronglyTypedIds.csproj +++ b/src/StronglyTypedIds/StronglyTypedIds.csproj @@ -3,7 +3,7 @@ netstandard2.0 false - disable + enable Tennisi.StronglyTypedId A source generator for creating strongly-typed IDs by decorating with a [StronglyTypedId] attribute diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Core3_1.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet6_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.DotNet7_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..58a2c4794 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdAttribute.Net4_8.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt new file mode 100644 index 000000000..4ea1be319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdBackingType.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Core3_1.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet6_0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.DotNet7_0.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt new file mode 100644 index 000000000..f9fffe68a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdConverter.Net4_8.verified.txt @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Core3_1.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet6_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.DotNet7_0.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..3df9e2e31 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdDefaultsAttribute.Net4_8.verified.txt @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt new file mode 100644 index 000000000..3eb5342b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Core3_1.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt new file mode 100644 index 000000000..3eb5342b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet6_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt new file mode 100644 index 000000000..3eb5342b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.DotNet7_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt new file mode 100644 index 000000000..3eb5342b4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.Net4_8.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif \ No newline at end of file diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt similarity index 99% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 7ee4bd7d4..806d124ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 7ee4bd7d4..806d124ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public System.Guid Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt new file mode 100644 index 000000000..806d124ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt similarity index 99% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index d65d51495..95c5442ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index d65d51495..95c5442ae 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public int Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt new file mode 100644 index 000000000..95c5442ae --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -0,0 +1,157 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt similarity index 98% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index 09643c593..f37d752d2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public long Value { get; } @@ -62,6 +62,7 @@ { long longValue => new MyTestId(longValue), int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), short shortValue => new MyTestId(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), @@ -69,6 +70,7 @@ } } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt new file mode 100644 index 000000000..f37d752d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 09643c593..f37d752d2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public long Value { get; } @@ -62,6 +62,7 @@ { long longValue => new MyTestId(longValue), int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), short shortValue => new MyTestId(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), @@ -69,6 +70,7 @@ } } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt new file mode 100644 index 000000000..f37d752d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 3fa5fad11..f37d752d2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -62,6 +62,7 @@ { long longValue => new MyTestId(longValue), int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), short shortValue => new MyTestId(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), @@ -69,6 +70,7 @@ } } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt similarity index 99% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt index caa78ba07..52fddbd6a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index caa78ba07..52fddbd6a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public MassTransit.NewId Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt new file mode 100644 index 000000000..52fddbd6a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -0,0 +1,165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt similarity index 99% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt index b45ca58f8..147d4c700 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index b45ca58f8..147d4c700 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -14,7 +14,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string? Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt new file mode 100644 index 000000000..147d4c700 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt similarity index 99% rename from test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt rename to test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt index 8612d81b5..2d01666a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.DotNet.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 8612d81b5..2d01666a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -13,7 +13,7 @@ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] - readonly partial struct MyTestId : System.IComparable, System.IEquatable + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable { public string Value { get; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt new file mode 100644 index 000000000..2d01666a6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId : System.IComparable, System.IEquatable, System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..bb6b344ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..508208c37 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..db59f66c1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..bef90429e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..a13e9bec6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..92cda7756 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..fad5ea0b5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..f72224715 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d6d801a99 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..295e92baf --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..f8d24bbf5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + long longValue when longValue < int.MaxValue => new MyTestId((int)longValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d3e50467b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..b4d9738e7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..d76d3afd2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..5d23b64a1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..e8afb0e98 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..45272d34a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..297090ba1 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int32"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7c016c3be --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt32()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..39f1e9331 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public int Value { get; } + + public MyTestId(int value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + int intValue => new MyTestId(intValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(int)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..1f4769435 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..1f4769435 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..1f4769435 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..1f4769435 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt index 35fd482b5..1f4769435 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt @@ -46,10 +46,12 @@ { long longValue => new MyTestId(longValue), int intValue => new MyTestId(intValue), + decimal decimalValue => new MyTestId((long)decimalValue), short shortValue => new MyTestId(shortValue), string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..cb5754863 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7052a3b27 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var result = serializer.Deserialize(reader); + return result.HasValue ? new MyTestId(result.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..c38fa63f6 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..13b9b1ac7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..9b553ad33 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..af1658c35 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..72b024dca --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "integer", Format = "int64"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..17a45333f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetInt64()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..e22d0478c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public long Value { get; } + + public MyTestId(long value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(0); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + long longValue => new MyTestId(longValue), + int intValue => new MyTestId(intValue), + short shortValue => new MyTestId(shortValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(long)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..23efe4b09 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value.ToGuid(); + } + + public override MyTestId Parse(object value) + { + return value switch + { + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..9114f2d54 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value.ToGuid(), + value => new MyTestId(MassTransit.NewId.FromGuid(value)), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..181d85e44 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value.ToGuid()); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..3a19fc65e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..b4c2d5867 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..8898353da --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..7e4892f41 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..699828755 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = "uuid"}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..3de0600ab --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value.ToGuid()); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..757eb4ebb --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public MassTransit.NewId Value { get; } + + public MyTestId(MassTransit.NewId value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); + public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || + sourceType == typeof(string) || base.CanConvertFrom + (context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + MassTransit.NewId newIdValue => new MyTestId(newIdValue), + System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(MassTransit.NewId)) + { + return idValue.Value; + } + + if (destinationType == typeof(System.Guid)) + { + return idValue.Value.ToGuid(); + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToGuid().ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c96f1e168 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + null => new MyTestId(null), + System.DBNull => new MyTestId(null), + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..e1a174104 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null) + : base( + id => id.Value!, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..9660c1fc0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer) + { + if (value is null) + { + serializer.Serialize(writer, null); + } + else + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..d779d1af4 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IComparable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..bb2e2c7d2 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IEquatable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..8a440b779 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId : System.IParsable + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..fe1e43665 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c85338e9a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = true; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..c049fb7f5 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + if (value.Value is null) + { + writer.WriteNullValue(); + } + else + { + writer.WriteStringValue(value.Value); + } + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..50b3c0585 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string? Value { get; } + + public MyTestId(string? value) + { + Value = value; + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value?.GetHashCode() ?? 0; + public override string? ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is null) + { + return new MyTestId(null); + } + + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..749dd1dbd --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -0,0 +1,61 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler + { + public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) + { + parameter.Value = value.Value; + } + + public override MyTestId Parse(object value) + { + return value switch + { + string stringValue => new MyTestId(stringValue), + _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), + }; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..05700f78d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter + { + public EfCoreValueConverter() : this(null) { } + public EfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) + : base( + id => id.Value, + value => new MyTestId(value), + mappingHints + ) { } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d7596bf2b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyTestId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyTestId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + if (objectType == typeof(MyTestId?)) + { + var value = serializer.Deserialize(reader); + + return value is null ? null : new MyTestId(value); + } + + return new MyTestId(serializer.Deserialize(reader)); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt new file mode 100644 index 000000000..4fae5139a --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IComparable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + public int CompareTo(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => 0, + (null, _) => -1, + (_, null) => 1, + (_, _) => Value.CompareTo(other.Value), + }; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt new file mode 100644 index 000000000..050bcc20b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IEquatable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt new file mode 100644 index 000000000..3ce01566b --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId : System.IParsable + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..0987c7d64 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..6e4590319 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + { + public void Apply(Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) + { + var idSchema = new Microsoft.OpenApi.Models.OpenApiSchema {Type = "string", Format = ""}; + schema.Type = idSchema.Type; + schema.Format = idSchema.Format; + schema.Example = idSchema.Example; + schema.Default = idSchema.Default; + schema.Properties = idSchema.Properties; + schema.Nullable = false; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..1396ccae3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(reader.GetString()); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt new file mode 100644 index 000000000..d35ac20a3 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))] + readonly partial struct MyTestId + { + public string Value { get; } + + public MyTestId(string value) + { + Value = value ?? throw new System.ArgumentNullException(nameof(value)); + } + + public static readonly MyTestId Empty = new MyTestId(string.Empty); + + public bool Equals(MyTestId other) + { + return (Value, other.Value) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + (_, _) => Value.Equals(other.Value), + }; + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value; + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + var stringValue = value as string; + if (stringValue is not null) + { + return new MyTestId(stringValue); + } + + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyTestId idValue) + { + if (destinationType == typeof(string)) + { + return idValue.Value; + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt new file mode 100644 index 000000000..ff61cdde7 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt new file mode 100644 index 000000000..dacf3158c --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt new file mode 100644 index 000000000..b71458e7e --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTestNamespace +{ + partial class OuterLayer1 + { + partial class OuterLayer0 + { + partial record InnerMost + { + [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))] + readonly partial struct MyTestId + { + public System.Guid Value { get; } + + public MyTestId(System.Guid value) + { + Value = value; + } + + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); + public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); + + public bool Equals(MyTestId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyTestId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); + public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyTestId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..56be7f36f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt @@ -0,0 +1,331 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..56be7f36f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt @@ -0,0 +1,331 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..56be7f36f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt @@ -0,0 +1,331 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..56be7f36f --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt @@ -0,0 +1,331 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..1d8786678 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..0e88633ad --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,306 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt new file mode 100644 index 000000000..8a5c7e797 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -0,0 +1,292 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt new file mode 100644 index 000000000..24997c508 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -0,0 +1,285 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) + { + return new MyId(System.Guid.Parse(reader.GetString())); + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, MyId value, System.Text.Json.JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt new file mode 100644 index 000000000..839a3cdf0 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -0,0 +1,313 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt new file mode 100644 index 000000000..c5dd24327 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -0,0 +1,334 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyTests.TestNameSpace +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt new file mode 100644 index 000000000..1d386be5d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt @@ -0,0 +1,438 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt new file mode 100644 index 000000000..1d386be5d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt @@ -0,0 +1,438 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt new file mode 100644 index 000000000..1d386be5d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt @@ -0,0 +1,438 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt new file mode 100644 index 000000000..1d386be5d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt @@ -0,0 +1,438 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V1 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace MyContracts.V2 +{ + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..91d1a1543 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -0,0 +1,337 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..91d1a1543 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -0,0 +1,337 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..91d1a1543 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -0,0 +1,337 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..91d1a1543 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -0,0 +1,337 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt new file mode 100644 index 000000000..82c6f9f8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -0,0 +1,343 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt new file mode 100644 index 000000000..82c6f9f8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -0,0 +1,343 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt new file mode 100644 index 000000000..82c6f9f8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -0,0 +1,343 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt new file mode 100644 index 000000000..82c6f9f8d --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -0,0 +1,343 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +namespace SomeNamespace +{ + partial class ParentClass where T: new() + { + partial record InnerClass + { + partial struct InnerStruct + { + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public System.Guid Value { get; } + + public MyId(System.Guid value) + { + Value = value; + } + + public static MyId New() => new MyId(System.Guid.NewGuid()); + public static readonly MyId Empty = new MyId(System.Guid.Empty); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + class MyIdTypeConverter : System.ComponentModel.TypeConverter + { + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) + { + return value switch + { + System.Guid guidValue => new MyId(guidValue), + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) + { + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) + { + if (value is MyId idValue) + { + if (destinationType == typeof(System.Guid)) + { + return idValue.Value; + } + + if (destinationType == typeof(string)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter + { + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(MyId); + } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + var id = (MyId)value; + serializer.Serialize(writer, id.Value); + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var guid = serializer.Deserialize(reader); + return guid.HasValue ? new MyId(guid.Value) : null; + } + } + } + } + } + } +} diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt new file mode 100644 index 000000000..e53221f19 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt @@ -0,0 +1,267 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt new file mode 100644 index 000000000..e53221f19 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt @@ -0,0 +1,267 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt new file mode 100644 index 000000000..e53221f19 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt @@ -0,0 +1,267 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt new file mode 100644 index 000000000..e53221f19 --- /dev/null +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt @@ -0,0 +1,267 @@ +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdAttribute : Attribute + { + /// + /// Make the struct a strongly typed ID + /// + /// The to use to store the strongly-typed ID value. + /// If not set, uses , which defaults to + /// Converters to create for serializing/deserializing the strongly-typed ID value. + /// If not set, uses , which defaults to + /// and + /// Interfaces and patterns the strongly typed id should implement + /// If not set, uses , which defaults to + /// and + public StronglyTypedIdAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The to use to store the strongly-typed ID value + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// JSON library used to serialize/deserialize strongly-typed ID value + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Used to control the default Place on partial structs to make the type a strongly-typed ID + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + [System.Diagnostics.Conditional("STRONGLY_TYPED_ID_USAGES")] + internal sealed class StronglyTypedIdDefaultsAttribute : Attribute + { + /// + /// Set the default values used for strongly typed ids + /// + /// The to use to store the strongly-typed ID value. + /// Defaults to + /// JSON library used to serialize/deserialize strongly-typed ID value. + /// Defaults to and + /// Interfaces and patterns the strongly typed id should implement + /// Defaults to and + public StronglyTypedIdDefaultsAttribute( + StronglyTypedIdBackingType backingType = StronglyTypedIdBackingType.Default, + StronglyTypedIdConverter converters = StronglyTypedIdConverter.Default, + StronglyTypedIdImplementations implementations = StronglyTypedIdImplementations.Default) + { + BackingType = backingType; + Converters = converters; + Implementations = implementations; + } + + /// + /// The default to use to store the strongly-typed ID values. + /// + public StronglyTypedIdBackingType BackingType { get; } + + /// + /// The default converters to create for serializing/deserializing strongly-typed ID values. + /// + public StronglyTypedIdConverter Converters { get; } + + /// + /// Interfaces and patterns the strongly typed id should implement + /// + public StronglyTypedIdImplementations Implementations { get; } + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// The to use to store the value of a strongly-typed ID + /// + internal enum StronglyTypedIdBackingType + { + /// + /// Use the default backing type (either the globally configured default, or Guid) + /// + Default = 0, + + Guid = 1, + Int = 2, + String = 3, + Long = 4, + NullableString = 5, + MassTransitNewId = 6, + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Converters used to to serialize/deserialize strongly-typed ID values + /// + [Flags] + internal enum StronglyTypedIdConverter + { + // Used with HasFlag, so needs to be 1, 2, 4 etc + + /// + /// Don't create any converters for the strongly typed ID + /// + None = 0, + + /// + /// Use the default converters for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + /// + /// Creates a for converting from the strongly typed ID to and from a string + /// + TypeConverter = 2, + + /// + /// Creates a Newtonsoft.Json.JsonConverter for serializing the strongly typed id to its primitive value + /// + NewtonsoftJson = 4, + + /// + /// Creates a System.Text.Json.Serialization.JsonConverter for serializing the strongly typed id to its primitive value + /// + SystemTextJson = 8, + + /// + /// Creates an EF Core Value Converter for extracting the primitive value + /// + EfCoreValueConverter = 16, + + /// + /// Creates a Dapper TypeHandler for converting to and from the type + /// + DapperTypeHandler = 32, + + /// + /// Creates a Swagger SchemaFilter for OpenApi documentation + /// + SwaggerSchemaFilter = 64, + + } +} +#endif +#if STRONGLY_TYPED_ID_EMBED_ATTRIBUTES + +using System; + +namespace StronglyTypedIds +{ + /// + /// Interfaces and patterns the strongly typed id should implement + /// + [Flags] + internal enum StronglyTypedIdImplementations + { + // Used with HasFlag, so needs to be 1, 2, 4, 8 etc + + /// + /// Don't implement any additional members for the strongly typed ID + /// + None = 0, + + /// + /// Use the default implementations for the strongly typed Id. + /// This will be the value provided in the , which falls back to + /// and + /// + Default = 1, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IEquatable = 2, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IComparable = 4, + + // ReSharper disable once InconsistentNaming + /// + /// Implement the interface + /// + IParsable = 8 + } +} + +#endif +//------------------------------------------------------------------------------ +// +// This code was generated by the StronglyTypedId source generator +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + + readonly partial struct MyId : System.IComparable, System.IEquatable + { + public int Value { get; } + + public MyId(int value) + { + Value = value; + } + + public static readonly MyId Empty = new MyId(0); + + public bool Equals(MyId other) => this.Value.Equals(other.Value); + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MyId other && Equals(other); + } + + public override int GetHashCode() => Value.GetHashCode(); + + public override string ToString() => Value.ToString(); + public static bool operator ==(MyId a, MyId b) => a.Equals(b); + public static bool operator !=(MyId a, MyId b) => !(a == b); + public int CompareTo(MyId other) => Value.CompareTo(other.Value); + } diff --git a/version.props b/version.props index eb9229570..02392dae1 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.10 + 1.0.11 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From ad8aadf69af952c8304c01e58e7c1707f5c5a80a Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 04:46:25 +0300 Subject: [PATCH 32/37] System.IFormatProvider --- src/StronglyTypedIds/EmbeddedSources.cs | 12 +++++++- .../SourceGenerationHelper.cs | 13 ++++++--- .../Templates/Guid/Guid_Parsable.cs | 6 ++-- .../Templates/Int/Int_Parsable.cs | 6 ++-- .../Templates/Long/Long_Parsable.cs | 6 ++-- ...IdCorrectly_type=Guid.Core3_1.verified.txt | 14 ++++++++++ ...Correctly_type=Guid.DotNet6_0.verified.txt | 14 ++++++++++ ...Correctly_type=Guid.DotNet7_0.verified.txt | 14 ++++++++++ ...lIdCorrectly_type=Guid.Net4_8.verified.txt | 14 ++++++++++ ...atesFullIdCorrectly_type=Guid.verified.txt | 14 ++++++++++ ...lIdCorrectly_type=Int.Core3_1.verified.txt | 14 ++++++++++ ...dCorrectly_type=Int.DotNet6_0.verified.txt | 14 ++++++++++ ...dCorrectly_type=Int.DotNet7_0.verified.txt | 14 ++++++++++ ...llIdCorrectly_type=Int.Net4_8.verified.txt | 14 ++++++++++ ...ratesFullIdCorrectly_type=Int.verified.txt | 14 ++++++++++ ...IdCorrectly_type=Long.Core3_1.verified.txt | 14 ++++++++++ ...Correctly_type=Long.DotNet6_0.verified.txt | 14 ++++++++++ ...Correctly_type=Long.DotNet7_0.verified.txt | 14 ++++++++++ ...lIdCorrectly_type=Long.Net4_8.verified.txt | 14 ++++++++++ ...atesFullIdCorrectly_type=Long.verified.txt | 14 ++++++++++ ...type=MassTransitNewId.Core3_1.verified.txt | 11 ++++++++ ...pe=MassTransitNewId.DotNet6_0.verified.txt | 11 ++++++++ ...pe=MassTransitNewId.DotNet7_0.verified.txt | 11 ++++++++ ..._type=MassTransitNewId.Net4_8.verified.txt | 11 ++++++++ ...rrectly_type=MassTransitNewId.verified.txt | 11 ++++++++ ...y_type=NullableString.Core3_1.verified.txt | 11 ++++++++ ...type=NullableString.DotNet6_0.verified.txt | 11 ++++++++ ...type=NullableString.DotNet7_0.verified.txt | 11 ++++++++ ...ly_type=NullableString.Net4_8.verified.txt | 11 ++++++++ ...Correctly_type=NullableString.verified.txt | 11 ++++++++ ...Correctly_type=String.Core3_1.verified.txt | 11 ++++++++ ...rrectly_type=String.DotNet6_0.verified.txt | 11 ++++++++ ...rrectly_type=String.DotNet7_0.verified.txt | 11 ++++++++ ...dCorrectly_type=String.Net4_8.verified.txt | 11 ++++++++ ...esFullIdCorrectly_type=String.verified.txt | 11 ++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ++++++++++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 14 ++++++++++ ...ype=Guid_c=None_i=IComparable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ++++++++++ ...t_c=None_i=IComparable.Net4_8.verified.txt | 14 ++++++++++ ...type=Int_c=None_i=IComparable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ++++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ++++++++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 14 ++++++++++ ...ype=Long_c=None_i=IComparable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 11 ++++++++ ...d_c=None_i=IComparable.Net4_8.verified.txt | 11 ++++++++ ...sitNewId_c=None_i=IComparable.verified.txt | 11 ++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 11 ++++++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 11 ++++++++ ...leString_c=None_i=IComparable.verified.txt | 11 ++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet6_0.verified.txt | 11 ++++++++ ...=None_i=IComparable.DotNet7_0.verified.txt | 11 ++++++++ ...g_c=None_i=IComparable.Net4_8.verified.txt | 11 ++++++++ ...e=String_c=None_i=IComparable.verified.txt | 11 ++++++++ ...ltIdInGlobalNamespace.Core3_1.verified.txt | 14 ++++++++++ ...IdInGlobalNamespace.DotNet6_0.verified.txt | 14 ++++++++++ ...IdInGlobalNamespace.DotNet7_0.verified.txt | 14 ++++++++++ ...ultIdInGlobalNamespace.Net4_8.verified.txt | 14 ++++++++++ ...ateDefaultIdInGlobalNamespace.verified.txt | 14 ++++++++++ ...InFileScopedNamespace.Core3_1.verified.txt | 14 ++++++++++ ...FileScopedNamespace.DotNet6_0.verified.txt | 14 ++++++++++ ...FileScopedNamespace.DotNet7_0.verified.txt | 14 ++++++++++ ...dInFileScopedNamespace.Net4_8.verified.txt | 14 ++++++++++ ...nerateIdInFileScopedNamespace.verified.txt | 14 ++++++++++ ...GenerateIdInNamespace.Core3_1.verified.txt | 14 ++++++++++ ...nerateIdInNamespace.DotNet6_0.verified.txt | 14 ++++++++++ ...nerateIdInNamespace.DotNet7_0.verified.txt | 14 ++++++++++ ...nGenerateIdInNamespace.Net4_8.verified.txt | 14 ++++++++++ ...ests.CanGenerateIdInNamespace.verified.txt | 14 ++++++++++ ...tJson, SystemTextJson.Core3_1.verified.txt | 14 ++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 14 ++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 14 ++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 14 ++++++++++ ...ewtonsoftJson, SystemTextJson.verified.txt | 14 ++++++++++ ...verter=NewtonsoftJson.Core3_1.verified.txt | 14 ++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 14 ++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 14 ++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 14 ++++++++++ ...Guid_converter=NewtonsoftJson.verified.txt | 14 ++++++++++ ...verter=SystemTextJson.Core3_1.verified.txt | 14 ++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 14 ++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 14 ++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 14 ++++++++++ ...Guid_converter=SystemTextJson.verified.txt | 14 ++++++++++ ...nverter=TypeConverter.Core3_1.verified.txt | 14 ++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 14 ++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 14 ++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 14 ++++++++++ ...=Guid_converter=TypeConverter.verified.txt | 14 ++++++++++ ...e=Guid_converter=null.Core3_1.verified.txt | 14 ++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 14 ++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 14 ++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 14 ++++++++++ ...ckingType=Guid_converter=null.verified.txt | 14 ++++++++++ ...tJson, SystemTextJson.Core3_1.verified.txt | 14 ++++++++++ ...son, SystemTextJson.DotNet6_0.verified.txt | 14 ++++++++++ ...son, SystemTextJson.DotNet7_0.verified.txt | 14 ++++++++++ ...ftJson, SystemTextJson.Net4_8.verified.txt | 14 ++++++++++ ...ewtonsoftJson, SystemTextJson.verified.txt | 14 ++++++++++ ...verter=NewtonsoftJson.Core3_1.verified.txt | 14 ++++++++++ ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 14 ++++++++++ ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 14 ++++++++++ ...nverter=NewtonsoftJson.Net4_8.verified.txt | 14 ++++++++++ ...Guid_converter=NewtonsoftJson.verified.txt | 14 ++++++++++ ...verter=SystemTextJson.Core3_1.verified.txt | 14 ++++++++++ ...rter=SystemTextJson.DotNet6_0.verified.txt | 14 ++++++++++ ...rter=SystemTextJson.DotNet7_0.verified.txt | 14 ++++++++++ ...nverter=SystemTextJson.Net4_8.verified.txt | 14 ++++++++++ ...Guid_converter=SystemTextJson.verified.txt | 14 ++++++++++ ...nverter=TypeConverter.Core3_1.verified.txt | 14 ++++++++++ ...erter=TypeConverter.DotNet6_0.verified.txt | 14 ++++++++++ ...erter=TypeConverter.DotNet7_0.verified.txt | 14 ++++++++++ ...onverter=TypeConverter.Net4_8.verified.txt | 14 ++++++++++ ...=Guid_converter=TypeConverter.verified.txt | 14 ++++++++++ ...e=Guid_converter=null.Core3_1.verified.txt | 14 ++++++++++ ...Guid_converter=null.DotNet6_0.verified.txt | 14 ++++++++++ ...Guid_converter=null.DotNet7_0.verified.txt | 14 ++++++++++ ...pe=Guid_converter=null.Net4_8.verified.txt | 14 ++++++++++ ...ckingType=Guid_converter=null.verified.txt | 14 ++++++++++ ...ltipleIdsWithSameName.Core3_1.verified.txt | 28 +++++++++++++++++++ ...ipleIdsWithSameName.DotNet6_0.verified.txt | 28 +++++++++++++++++++ ...ipleIdsWithSameName.DotNet7_0.verified.txt | 28 +++++++++++++++++++ ...ultipleIdsWithSameName.Net4_8.verified.txt | 28 +++++++++++++++++++ ...nerateMultipleIdsWithSameName.verified.txt | 28 +++++++++++++++++++ ...dInFileScopeNamespace.Core3_1.verified.txt | 14 ++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 14 ++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 14 ++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 14 ++++++++++ ...eNestedIdInFileScopeNamespace.verified.txt | 14 ++++++++++ ...dInFileScopeNamespace.Core3_1.verified.txt | 14 ++++++++++ ...nFileScopeNamespace.DotNet6_0.verified.txt | 14 ++++++++++ ...nFileScopeNamespace.DotNet7_0.verified.txt | 14 ++++++++++ ...IdInFileScopeNamespace.Net4_8.verified.txt | 14 ++++++++++ ...yNestedIdInFileScopeNamespace.verified.txt | 14 ++++++++++ ...sUsingGlobalAttribute.Core3_1.verified.txt | 14 ++++++++++ ...singGlobalAttribute.DotNet6_0.verified.txt | 14 ++++++++++ ...singGlobalAttribute.DotNet7_0.verified.txt | 14 ++++++++++ ...tsUsingGlobalAttribute.Net4_8.verified.txt | 14 ++++++++++ ...eDefaultsUsingGlobalAttribute.verified.txt | 14 ++++++++++ version.props | 2 +- 151 files changed, 2040 insertions(+), 15 deletions(-) diff --git a/src/StronglyTypedIds/EmbeddedSources.cs b/src/StronglyTypedIds/EmbeddedSources.cs index 1c6d7e0b5..3dc1da306 100644 --- a/src/StronglyTypedIds/EmbeddedSources.cs +++ b/src/StronglyTypedIds/EmbeddedSources.cs @@ -25,6 +25,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_SwaggerSchemaFilter.cs"), false ); @@ -38,6 +39,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_SwaggerSchemaFilter.cs"), false ); @@ -51,6 +53,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_SwaggerSchemaFilter.cs"), false ); @@ -64,6 +67,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_SwaggerSchemaFilter.cs"), false ); @@ -77,6 +81,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_SwaggerSchemaFilter.cs"), true ); @@ -90,6 +95,7 @@ internal static class EmbeddedSources LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_EfCoreValueConverter.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_DapperTypeHandler.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_IComparable.cs"), + LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_Parsable.cs"), LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_SwaggerSchemaFilter.cs"), false ); @@ -126,6 +132,8 @@ public readonly struct ResourceCollection public string DapperTypeHandler { get; } public string Comparable { get; } + public string Parsable { get; } + public ResourceCollection( string header, string baseId, @@ -135,6 +143,7 @@ public ResourceCollection( string efCoreValueConverter, string dapperTypeHandler, string comparable, + string parsable, string swaggerSchemaFilter, bool nullableEnable) { @@ -146,6 +155,7 @@ public ResourceCollection( EfCoreValueConverter = efCoreValueConverter; DapperTypeHandler = dapperTypeHandler; Comparable = comparable; + Parsable = parsable; NullableEnable = nullableEnable; Header = header; } @@ -163,4 +173,4 @@ internal static string LoadTemplateForEmitting(string resourceName) #endif"; } } -} \ No newline at end of file +} diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index 0a59dc895..5dea326c2 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -73,7 +73,7 @@ static string CreateId( var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable); var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable); - var useParsable = implementations.IsSet(StronglyTypedIdImplementations.IParsable); + var useIParsable = implementations.IsSet(StronglyTypedIdImplementations.IParsable); var parentsCount = 0; @@ -131,7 +131,7 @@ static string CreateId( sb.Append(resources.BaseId); - ReplaceInterfaces(sb, useIEquatable, useIComparable, useParsable); + ReplaceInterfaces(sb, useIEquatable, useIComparable, useIParsable); // IEquatable is already implemented whether or not the interface is implemented @@ -140,6 +140,11 @@ static string CreateId( sb.AppendLine(resources.Comparable); } + if (useIComparable) + { + sb.AppendLine(resources.Parsable); + } + if (useEfCoreValueConverter) { sb.AppendLine(resources.EfCoreValueConverter); @@ -186,7 +191,7 @@ static string CreateId( return sb.ToString(); } - private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool useIComparable, bool useParsable) + private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool useIComparable, bool useIParsable) { var interfaces = new List(); @@ -200,7 +205,7 @@ private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool interfaces.Add("System.IEquatable"); } - if (useParsable) + if (useIParsable) { interfaces.Add("System.IParsable"); } diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs index e9d354a67..b84340d2c 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs @@ -1,13 +1,13 @@  - public static TESTID Parse(string s, IFormatProvider? provider) + public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(Guid.Parse(s)); } - public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { long res = 0; - var ok = Guid.TryParse(out res); + var ok = Guid.TryParse(s, out res); result = new TESTID(res); return ok; } diff --git a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs index 9369b51a6..6648a6d4a 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs @@ -1,13 +1,13 @@  - public static TESTID Parse(string s, IFormatProvider? provider) + public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(int.Parse(s)); } - public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { int res = 0; - var ok = int.TryParse(out res); + var ok = int.TryParse(s, out res); result = new TESTID(res); return ok; } diff --git a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs index 0b8f613e8..661fe7e48 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs @@ -1,13 +1,13 @@  - public static TESTID Parse(string s, IFormatProvider? provider) + public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(long.Parse(s)); } - public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) + public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { long res = 0; - var ok = long.TryParse(out res); + var ok = long.TryParse(s, out res); result = new TESTID(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 806d124ae..65bb437cc 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -39,6 +39,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt index 806d124ae..65bb437cc 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -39,6 +39,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 806d124ae..65bb437cc 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -39,6 +39,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt index 806d124ae..65bb437cc 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -39,6 +39,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 806d124ae..65bb437cc 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -39,6 +39,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index 95c5442ae..60afa982b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt index 95c5442ae..60afa982b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 95c5442ae..60afa982b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt index 95c5442ae..60afa982b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index 95c5442ae..60afa982b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index f37d752d2..9c2d44dad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt index f37d752d2..9c2d44dad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index f37d752d2..9c2d44dad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt index f37d752d2..9c2d44dad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index f37d752d2..9c2d44dad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -38,6 +38,20 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt index 52fddbd6a..c3f1cc375 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -39,6 +39,17 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt index 52fddbd6a..c3f1cc375 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -39,6 +39,17 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index 52fddbd6a..c3f1cc375 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -39,6 +39,17 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt index 52fddbd6a..c3f1cc375 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -39,6 +39,17 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index 52fddbd6a..c3f1cc375 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -39,6 +39,17 @@ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt index 147d4c700..f19a52499 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt index 147d4c700..f19a52499 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index 147d4c700..f19a52499 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt index 147d4c700..f19a52499 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index 147d4c700..f19a52499 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt index 2d01666a6..151f2796e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt index 2d01666a6..151f2796e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 2d01666a6..151f2796e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt index 2d01666a6..151f2796e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 2d01666a6..151f2796e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -56,6 +56,17 @@ }; } + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + + public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter { public EfCoreValueConverter() : this(null) { } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt index bef90429e..c4c2759bb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt @@ -34,4 +34,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt index bef90429e..c4c2759bb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt @@ -34,4 +34,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt index bef90429e..c4c2759bb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt @@ -34,4 +34,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt index bef90429e..c4c2759bb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt @@ -34,4 +34,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt index bef90429e..c4c2759bb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt @@ -34,4 +34,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt index d76d3afd2..6ae8cdc30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt index d76d3afd2..6ae8cdc30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt index d76d3afd2..6ae8cdc30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt index d76d3afd2..6ae8cdc30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt index d76d3afd2..6ae8cdc30 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt index c38fa63f6..80c989cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt index c38fa63f6..80c989cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt index c38fa63f6..80c989cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt index c38fa63f6..80c989cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt index c38fa63f6..80c989cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt @@ -33,4 +33,18 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt index 3a19fc65e..f9fbc5865 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt @@ -34,4 +34,15 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt index 3a19fc65e..f9fbc5865 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt @@ -34,4 +34,15 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt index 3a19fc65e..f9fbc5865 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt @@ -34,4 +34,15 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt index 3a19fc65e..f9fbc5865 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt @@ -34,4 +34,15 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt index 3a19fc65e..f9fbc5865 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt @@ -34,4 +34,15 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt index d779d1af4..e9b6c8012 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt index d779d1af4..e9b6c8012 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt index d779d1af4..e9b6c8012 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt index d779d1af4..e9b6c8012 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt index d779d1af4..e9b6c8012 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt index 4fae5139a..69d7d0028 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt index 4fae5139a..69d7d0028 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt index 4fae5139a..69d7d0028 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt index 4fae5139a..69d7d0028 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt index 4fae5139a..69d7d0028 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt @@ -51,4 +51,15 @@ (_, _) => Value.CompareTo(other.Value), }; } + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt index 56be7f36f..56d444942 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt @@ -268,6 +268,20 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt index 56be7f36f..56d444942 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt @@ -268,6 +268,20 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt index 56be7f36f..56d444942 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt @@ -268,6 +268,20 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt index 56be7f36f..56d444942 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt @@ -268,6 +268,20 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 56be7f36f..56d444942 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -268,6 +268,20 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 1d8786678..3f9bca7ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -270,6 +270,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 0e88633ad..e39e6bd14 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 8a5c7e797..9ecd489d6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 24997c508..12e0a4d5f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 839a3cdf0..715337914 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -269,6 +269,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index c5dd24327..99131e620 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -270,6 +270,20 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt index 1d386be5d..e2edfe933 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt @@ -270,6 +270,20 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -374,6 +388,20 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt index 1d386be5d..e2edfe933 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt @@ -270,6 +270,20 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -374,6 +388,20 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt index 1d386be5d..e2edfe933 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt @@ -270,6 +270,20 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -374,6 +388,20 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt index 1d386be5d..e2edfe933 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt @@ -270,6 +270,20 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -374,6 +388,20 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index 1d386be5d..e2edfe933 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -270,6 +270,20 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -374,6 +388,20 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt index 91d1a1543..6a3d1416d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -272,6 +272,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index 91d1a1543..6a3d1416d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -272,6 +272,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index 91d1a1543..6a3d1416d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -272,6 +272,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt index 91d1a1543..6a3d1416d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -272,6 +272,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 91d1a1543..6a3d1416d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -272,6 +272,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt index 82c6f9f8d..b0f1a125f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -276,6 +276,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index 82c6f9f8d..b0f1a125f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -276,6 +276,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index 82c6f9f8d..b0f1a125f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -276,6 +276,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt index 82c6f9f8d..b0f1a125f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -276,6 +276,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index 82c6f9f8d..b0f1a125f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -276,6 +276,20 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyId(res); + return ok; + } + + class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt index e53221f19..882234f6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt @@ -264,4 +264,18 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt index e53221f19..882234f6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt @@ -264,4 +264,18 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt index e53221f19..882234f6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt @@ -264,4 +264,18 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt index e53221f19..882234f6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt @@ -264,4 +264,18 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index e53221f19..882234f6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -264,4 +264,18 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); + + public static MyId Parse(string s, System.IFormatProvider? provider) + { + return new MyId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyId(res); + return ok; + } + } diff --git a/version.props b/version.props index 02392dae1..b676d1b2e 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.11 + 1.0.13 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From eba59a8d4f4de78500e1d3d203837619b0881395 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 05:04:30 +0300 Subject: [PATCH 33/37] fix --- src/StronglyTypedIds/Constants.cs | 4 ++- src/StronglyTypedIds/EmbeddedSources.cs | 1 - .../SourceGenerationHelper.cs | 2 +- ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ---------- ...d_c=None_i=IComparable.Net4_8.verified.txt | 14 ---------- ...ype=Guid_c=None_i=IComparable.verified.txt | 14 ---------- ...id_c=None_i=IParsable.Core3_1.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 14 ++++++++++ ...uid_c=None_i=IParsable.Net4_8.verified.txt | 14 ++++++++++ ..._type=Guid_c=None_i=IParsable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ---------- ...t_c=None_i=IComparable.Net4_8.verified.txt | 14 ---------- ...type=Int_c=None_i=IComparable.verified.txt | 14 ---------- ...nt_c=None_i=IParsable.Core3_1.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 14 ++++++++++ ...Int_c=None_i=IParsable.Net4_8.verified.txt | 14 ++++++++++ ...y_type=Int_c=None_i=IParsable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet6_0.verified.txt | 14 ---------- ...=None_i=IComparable.DotNet7_0.verified.txt | 14 ---------- ...g_c=None_i=IComparable.Net4_8.verified.txt | 14 ---------- ...ype=Long_c=None_i=IComparable.verified.txt | 14 ---------- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 14 ++++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 14 ++++++++++ ...ong_c=None_i=IParsable.Net4_8.verified.txt | 14 ++++++++++ ..._type=Long_c=None_i=IParsable.verified.txt | 14 ++++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 -------- ...=None_i=IComparable.DotNet6_0.verified.txt | 11 -------- ...=None_i=IComparable.DotNet7_0.verified.txt | 11 -------- ...d_c=None_i=IComparable.Net4_8.verified.txt | 11 -------- ...sitNewId_c=None_i=IComparable.verified.txt | 11 -------- ...Id_c=None_i=IParsable.Core3_1.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 11 ++++++++ ...wId_c=None_i=IParsable.Net4_8.verified.txt | 11 ++++++++ ...ansitNewId_c=None_i=IParsable.verified.txt | 11 ++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 -------- ...=None_i=IComparable.DotNet6_0.verified.txt | 11 -------- ...=None_i=IComparable.DotNet7_0.verified.txt | 11 -------- ...g_c=None_i=IComparable.Net4_8.verified.txt | 11 -------- ...leString_c=None_i=IComparable.verified.txt | 11 -------- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 11 ++++++++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 11 ++++++++ ...ableString_c=None_i=IParsable.verified.txt | 11 ++++++++ ..._c=None_i=IComparable.Core3_1.verified.txt | 11 -------- ...=None_i=IComparable.DotNet6_0.verified.txt | 11 -------- ...=None_i=IComparable.DotNet7_0.verified.txt | 11 -------- ...g_c=None_i=IComparable.Net4_8.verified.txt | 11 -------- ...e=String_c=None_i=IComparable.verified.txt | 11 -------- ...ng_c=None_i=IParsable.Core3_1.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet6_0.verified.txt | 11 ++++++++ ..._c=None_i=IParsable.DotNet7_0.verified.txt | 11 ++++++++ ...ing_c=None_i=IParsable.Net4_8.verified.txt | 11 ++++++++ ...ype=String_c=None_i=IParsable.verified.txt | 11 ++++++++ ...ltIdInGlobalNamespace.Core3_1.verified.txt | 14 ---------- ...IdInGlobalNamespace.DotNet6_0.verified.txt | 14 ---------- ...IdInGlobalNamespace.DotNet7_0.verified.txt | 14 ---------- ...ultIdInGlobalNamespace.Net4_8.verified.txt | 14 ---------- ...ateDefaultIdInGlobalNamespace.verified.txt | 14 ---------- ...InFileScopedNamespace.Core3_1.verified.txt | 14 ---------- ...FileScopedNamespace.DotNet6_0.verified.txt | 14 ---------- ...FileScopedNamespace.DotNet7_0.verified.txt | 14 ---------- ...dInFileScopedNamespace.Net4_8.verified.txt | 14 ---------- ...nerateIdInFileScopedNamespace.verified.txt | 14 ---------- ...GenerateIdInNamespace.Core3_1.verified.txt | 14 ---------- ...nerateIdInNamespace.DotNet6_0.verified.txt | 14 ---------- ...nerateIdInNamespace.DotNet7_0.verified.txt | 14 ---------- ...nGenerateIdInNamespace.Net4_8.verified.txt | 14 ---------- ...ests.CanGenerateIdInNamespace.verified.txt | 14 ---------- ...tJson, SystemTextJson.Core3_1.verified.txt | 14 ---------- ...son, SystemTextJson.DotNet6_0.verified.txt | 14 ---------- ...son, SystemTextJson.DotNet7_0.verified.txt | 14 ---------- ...ftJson, SystemTextJson.Net4_8.verified.txt | 14 ---------- ...ewtonsoftJson, SystemTextJson.verified.txt | 14 ---------- ...verter=NewtonsoftJson.Core3_1.verified.txt | 14 ---------- ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 14 ---------- ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 14 ---------- ...nverter=NewtonsoftJson.Net4_8.verified.txt | 14 ---------- ...Guid_converter=NewtonsoftJson.verified.txt | 14 ---------- ...verter=SystemTextJson.Core3_1.verified.txt | 14 ---------- ...rter=SystemTextJson.DotNet6_0.verified.txt | 14 ---------- ...rter=SystemTextJson.DotNet7_0.verified.txt | 14 ---------- ...nverter=SystemTextJson.Net4_8.verified.txt | 14 ---------- ...Guid_converter=SystemTextJson.verified.txt | 14 ---------- ...nverter=TypeConverter.Core3_1.verified.txt | 14 ---------- ...erter=TypeConverter.DotNet6_0.verified.txt | 14 ---------- ...erter=TypeConverter.DotNet7_0.verified.txt | 14 ---------- ...onverter=TypeConverter.Net4_8.verified.txt | 14 ---------- ...=Guid_converter=TypeConverter.verified.txt | 14 ---------- ...e=Guid_converter=null.Core3_1.verified.txt | 14 ---------- ...Guid_converter=null.DotNet6_0.verified.txt | 14 ---------- ...Guid_converter=null.DotNet7_0.verified.txt | 14 ---------- ...pe=Guid_converter=null.Net4_8.verified.txt | 14 ---------- ...ckingType=Guid_converter=null.verified.txt | 14 ---------- ...tJson, SystemTextJson.Core3_1.verified.txt | 14 ---------- ...son, SystemTextJson.DotNet6_0.verified.txt | 14 ---------- ...son, SystemTextJson.DotNet7_0.verified.txt | 14 ---------- ...ftJson, SystemTextJson.Net4_8.verified.txt | 14 ---------- ...ewtonsoftJson, SystemTextJson.verified.txt | 14 ---------- ...verter=NewtonsoftJson.Core3_1.verified.txt | 14 ---------- ...rter=NewtonsoftJson.DotNet6_0.verified.txt | 14 ---------- ...rter=NewtonsoftJson.DotNet7_0.verified.txt | 14 ---------- ...nverter=NewtonsoftJson.Net4_8.verified.txt | 14 ---------- ...Guid_converter=NewtonsoftJson.verified.txt | 14 ---------- ...verter=SystemTextJson.Core3_1.verified.txt | 14 ---------- ...rter=SystemTextJson.DotNet6_0.verified.txt | 14 ---------- ...rter=SystemTextJson.DotNet7_0.verified.txt | 14 ---------- ...nverter=SystemTextJson.Net4_8.verified.txt | 14 ---------- ...Guid_converter=SystemTextJson.verified.txt | 14 ---------- ...nverter=TypeConverter.Core3_1.verified.txt | 14 ---------- ...erter=TypeConverter.DotNet6_0.verified.txt | 14 ---------- ...erter=TypeConverter.DotNet7_0.verified.txt | 14 ---------- ...onverter=TypeConverter.Net4_8.verified.txt | 14 ---------- ...=Guid_converter=TypeConverter.verified.txt | 14 ---------- ...e=Guid_converter=null.Core3_1.verified.txt | 14 ---------- ...Guid_converter=null.DotNet6_0.verified.txt | 14 ---------- ...Guid_converter=null.DotNet7_0.verified.txt | 14 ---------- ...pe=Guid_converter=null.Net4_8.verified.txt | 14 ---------- ...ckingType=Guid_converter=null.verified.txt | 14 ---------- ...ltipleIdsWithSameName.Core3_1.verified.txt | 28 ------------------- ...ipleIdsWithSameName.DotNet6_0.verified.txt | 28 ------------------- ...ipleIdsWithSameName.DotNet7_0.verified.txt | 28 ------------------- ...ultipleIdsWithSameName.Net4_8.verified.txt | 28 ------------------- ...nerateMultipleIdsWithSameName.verified.txt | 28 ------------------- ...dInFileScopeNamespace.Core3_1.verified.txt | 14 ---------- ...nFileScopeNamespace.DotNet6_0.verified.txt | 14 ---------- ...nFileScopeNamespace.DotNet7_0.verified.txt | 14 ---------- ...IdInFileScopeNamespace.Net4_8.verified.txt | 14 ---------- ...eNestedIdInFileScopeNamespace.verified.txt | 14 ---------- ...dInFileScopeNamespace.Core3_1.verified.txt | 14 ---------- ...nFileScopeNamespace.DotNet6_0.verified.txt | 14 ---------- ...nFileScopeNamespace.DotNet7_0.verified.txt | 14 ---------- ...IdInFileScopeNamespace.Net4_8.verified.txt | 14 ---------- ...yNestedIdInFileScopeNamespace.verified.txt | 14 ---------- ...sUsingGlobalAttribute.Core3_1.verified.txt | 14 ---------- ...singGlobalAttribute.DotNet6_0.verified.txt | 14 ---------- ...singGlobalAttribute.DotNet7_0.verified.txt | 14 ---------- ...tsUsingGlobalAttribute.Net4_8.verified.txt | 14 ---------- ...eDefaultsUsingGlobalAttribute.verified.txt | 14 ---------- version.props | 2 +- 149 files changed, 380 insertions(+), 1639 deletions(-) diff --git a/src/StronglyTypedIds/Constants.cs b/src/StronglyTypedIds/Constants.cs index 5cb590a6b..62911130a 100644 --- a/src/StronglyTypedIds/Constants.cs +++ b/src/StronglyTypedIds/Constants.cs @@ -1,7 +1,9 @@ +using System; + namespace StronglyTypedIds { internal static class Constants { public const string Usage = nameof(Usage); } -} \ No newline at end of file +} diff --git a/src/StronglyTypedIds/EmbeddedSources.cs b/src/StronglyTypedIds/EmbeddedSources.cs index 3dc1da306..bcd8f008a 100644 --- a/src/StronglyTypedIds/EmbeddedSources.cs +++ b/src/StronglyTypedIds/EmbeddedSources.cs @@ -131,7 +131,6 @@ public readonly struct ResourceCollection public string EfCoreValueConverter { get; } public string DapperTypeHandler { get; } public string Comparable { get; } - public string Parsable { get; } public ResourceCollection( diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs index 5dea326c2..265225909 100644 --- a/src/StronglyTypedIds/SourceGenerationHelper.cs +++ b/src/StronglyTypedIds/SourceGenerationHelper.cs @@ -140,7 +140,7 @@ static string CreateId( sb.AppendLine(resources.Comparable); } - if (useIComparable) + if (useIParsable) { sb.AppendLine(resources.Parsable); } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt index c4c2759bb..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt @@ -34,18 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt index c4c2759bb..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt @@ -34,18 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt index c4c2759bb..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt @@ -34,18 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt index c4c2759bb..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt @@ -34,18 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt index c4c2759bb..bef90429e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt @@ -34,18 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt index 92cda7756..1694a026b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -33,4 +33,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt index 92cda7756..1694a026b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -33,4 +33,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt index 92cda7756..1694a026b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -33,4 +33,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt index 92cda7756..1694a026b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -33,4 +33,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index 92cda7756..1694a026b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -33,4 +33,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(Guid.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = Guid.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt index 6ae8cdc30..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt index 6ae8cdc30..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt index 6ae8cdc30..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt index 6ae8cdc30..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt index 6ae8cdc30..d76d3afd2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt index e8afb0e98..5abfad40b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt index e8afb0e98..5abfad40b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt index e8afb0e98..5abfad40b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt index e8afb0e98..5abfad40b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index e8afb0e98..5abfad40b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(int.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + int res = 0; + var ok = int.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt index 80c989cb9..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(long.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = long.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt index 80c989cb9..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(long.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = long.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt index 80c989cb9..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(long.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = long.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt index 80c989cb9..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(long.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = long.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt index 80c989cb9..c38fa63f6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt @@ -33,18 +33,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, System.IFormatProvider? provider) - { - return new MyTestId(long.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) - { - long res = 0; - var ok = long.TryParse(s, out res); - result = new MyTestId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt index 9b553ad33..4acb87d6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt index 9b553ad33..4acb87d6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt index 9b553ad33..4acb87d6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt index 9b553ad33..4acb87d6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 9b553ad33..4acb87d6f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -32,4 +32,18 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, System.IFormatProvider? provider) + { + return new MyTestId(long.Parse(s)); + } + + public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) + { + long res = 0; + var ok = long.TryParse(s, out res); + result = new MyTestId(res); + return ok; + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt index f9fbc5865..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt @@ -34,15 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt index f9fbc5865..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt @@ -34,15 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt index f9fbc5865..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt @@ -34,15 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt index f9fbc5865..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt @@ -34,15 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt index f9fbc5865..3a19fc65e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt @@ -34,15 +34,4 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt index 8898353da..ce7836cb8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt @@ -33,4 +33,15 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt index 8898353da..ce7836cb8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt @@ -33,4 +33,15 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt index 8898353da..ce7836cb8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt @@ -33,4 +33,15 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt index 8898353da..ce7836cb8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt @@ -33,4 +33,15 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index 8898353da..ce7836cb8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -33,4 +33,15 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt index e9b6c8012..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt index e9b6c8012..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt index e9b6c8012..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt index e9b6c8012..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt index e9b6c8012..d779d1af4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt index 8a440b779..f665bb078 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt @@ -41,4 +41,15 @@ public override string? ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt index 8a440b779..f665bb078 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt @@ -41,4 +41,15 @@ public override string? ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt index 8a440b779..f665bb078 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt @@ -41,4 +41,15 @@ public override string? ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt index 8a440b779..f665bb078 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt @@ -41,4 +41,15 @@ public override string? ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index 8a440b779..f665bb078 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -41,4 +41,15 @@ public override string? ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt index 69d7d0028..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt index 69d7d0028..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt index 69d7d0028..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt index 69d7d0028..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt index 69d7d0028..4fae5139a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt @@ -51,15 +51,4 @@ (_, _) => Value.CompareTo(other.Value), }; } - - public static MyTestId Parse(string s, IFormatProvider? provider) - { - throw new NotImplementedException(); - } - - public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) - { - throw new NotImplementedException(); - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt index 3ce01566b..99577f35a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt @@ -41,4 +41,15 @@ public override string ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt index 3ce01566b..99577f35a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt @@ -41,4 +41,15 @@ public override string ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt index 3ce01566b..99577f35a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt @@ -41,4 +41,15 @@ public override string ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt index 3ce01566b..99577f35a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt @@ -41,4 +41,15 @@ public override string ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index 3ce01566b..99577f35a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -41,4 +41,15 @@ public override string ToString() => Value; public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + + public static MyTestId Parse(string s, IFormatProvider? provider) + { + throw new NotImplementedException(); + } + + public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) + { + throw new NotImplementedException(); + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt index 56d444942..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt @@ -268,20 +268,6 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt index 56d444942..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt @@ -268,20 +268,6 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt index 56d444942..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt @@ -268,20 +268,6 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt index 56d444942..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt @@ -268,20 +268,6 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 56d444942..56be7f36f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -268,20 +268,6 @@ namespace StronglyTypedIds public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 3f9bca7ad..1d8786678 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -270,20 +270,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index e39e6bd14..0e88633ad 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 9ecd489d6..8a5c7e797 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter { public override bool CanConvert(System.Type objectType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 12e0a4d5f..24997c508 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter { public override MyId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 715337914..839a3cdf0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -269,20 +269,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index 99131e620..c5dd24327 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -270,20 +270,6 @@ namespace MyTests.TestNameSpace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt index e2edfe933..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt @@ -270,20 +270,6 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -388,20 +374,6 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt index e2edfe933..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt @@ -270,20 +270,6 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -388,20 +374,6 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt index e2edfe933..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt @@ -270,20 +270,6 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -388,20 +374,6 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt index e2edfe933..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt @@ -270,20 +270,6 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -388,20 +374,6 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index e2edfe933..1d386be5d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -270,20 +270,6 @@ namespace MyContracts.V1 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) @@ -388,20 +374,6 @@ namespace MyContracts.V2 public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt index 6a3d1416d..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -272,20 +272,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index 6a3d1416d..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -272,20 +272,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index 6a3d1416d..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -272,20 +272,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt index 6a3d1416d..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -272,20 +272,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 6a3d1416d..91d1a1543 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -272,20 +272,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt index b0f1a125f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -276,20 +276,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index b0f1a125f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -276,20 +276,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index b0f1a125f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -276,20 +276,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt index b0f1a125f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -276,20 +276,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index b0f1a125f..82c6f9f8d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -276,20 +276,6 @@ namespace SomeNamespace public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(Guid.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - long res = 0; - var ok = Guid.TryParse(s, out res); - result = new MyId(res); - return ok; - } - - class MyIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt index 882234f6f..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt @@ -264,18 +264,4 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt index 882234f6f..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt @@ -264,18 +264,4 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt index 882234f6f..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt @@ -264,18 +264,4 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt index 882234f6f..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt @@ -264,18 +264,4 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyId(res); - return ok; - } - } diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index 882234f6f..e53221f19 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -264,18 +264,4 @@ namespace StronglyTypedIds public static bool operator ==(MyId a, MyId b) => a.Equals(b); public static bool operator !=(MyId a, MyId b) => !(a == b); public int CompareTo(MyId other) => Value.CompareTo(other.Value); - - public static MyId Parse(string s, System.IFormatProvider? provider) - { - return new MyId(int.Parse(s)); - } - - public static bool TryParse(string? s, System.IFormatProvider? provider, out MyId result) - { - int res = 0; - var ok = int.TryParse(s, out res); - result = new MyId(res); - return ok; - } - } diff --git a/version.props b/version.props index b676d1b2e..f5916cd40 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.13 + 1.0.14 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From b70f7583390e6a8d39bb0e6f5c589bc2babdfbe8 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 05:21:39 +0300 Subject: [PATCH 34/37] nullable --- .../StronglyTypedIds.Attributes.csproj | 2 +- version.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj index 5fd0485d3..415ff92f1 100644 --- a/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj +++ b/src/StronglyTypedIds.Attributes/StronglyTypedIds.Attributes.csproj @@ -2,8 +2,8 @@ netstandard2.0 - enable StronglyTypedIds + enable false diff --git a/version.props b/version.props index f5916cd40..39cee7c3d 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.14 + 1.0.16 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From 681af0f150ae908479771f10166c07d3611be087 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 07:22:29 +0300 Subject: [PATCH 35/37] combinations of #nullable enable/disable --- src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs | 3 ++- src/StronglyTypedIds/Templates/Int/Int_Parsable.cs | 3 ++- src/StronglyTypedIds/Templates/Long/Long_Parsable.cs | 3 ++- ...sts.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt | 3 ++- ...s.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt | 3 ++- ...s.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt | 3 ++- ...ests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt | 3 ++- ...apshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt | 3 ++- ...ests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt | 3 ++- ...ts.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt | 3 ++- ...ts.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt | 3 ++- ...Tests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt | 3 ++- ...napshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt | 3 ++- ...sts.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt | 3 ++- ...s.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt | 3 ++- ...s.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt | 3 ++- ...ests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt | 3 ++- ...apshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt | 3 ++- ...Correctly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt | 3 ++- ...rrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt | 3 ++- ...rrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt | 3 ++- ...dCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt | 3 ++- ...eratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt | 3 ++- ...dCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt | 3 ++- ...orrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt | 3 ++- ...orrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt | 3 ++- ...IdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt | 3 ++- ...neratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt | 3 ++- ...Correctly_type=Long_c=None_i=IParsable.Core3_1.verified.txt | 3 ++- ...rrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt | 3 ++- ...rrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt | 3 ++- ...dCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt | 3 ++- ...eratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt | 3 ++- version.props | 2 +- 34 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs index b84340d2c..f05831196 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs @@ -1,4 +1,4 @@ - +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(Guid.Parse(s)); @@ -11,3 +11,4 @@ public static bool TryParse(string? s, System.IFormatProvider? provider, out TES result = new TESTID(res); return ok; } +#nullable disable diff --git a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs index 6648a6d4a..2632b7145 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs @@ -1,4 +1,4 @@ - +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(int.Parse(s)); @@ -11,3 +11,4 @@ public static bool TryParse(string? s, System.IFormatProvider? provider, out TES result = new TESTID(res); return ok; } +#nullable disable diff --git a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs index 661fe7e48..be4cbe4a4 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs @@ -1,4 +1,4 @@ - +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { return new TESTID(long.Parse(s)); @@ -11,3 +11,4 @@ public static bool TryParse(string? s, System.IFormatProvider? provider, out TES result = new TESTID(res); return ok; } +#nullable disable diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 65bb437cc..04e282a91 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -38,7 +38,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -51,6 +51,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt index 65bb437cc..04e282a91 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -38,7 +38,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -51,6 +51,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 65bb437cc..04e282a91 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -38,7 +38,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -51,6 +51,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt index 65bb437cc..04e282a91 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -38,7 +38,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -51,6 +51,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 65bb437cc..04e282a91 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -38,7 +38,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -51,6 +51,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index 60afa982b..5f076338a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt index 60afa982b..5f076338a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 60afa982b..5f076338a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt index 60afa982b..5f076338a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index 60afa982b..5f076338a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index 9c2d44dad..86c4241a0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt index 9c2d44dad..86c4241a0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 9c2d44dad..86c4241a0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt index 9c2d44dad..86c4241a0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 9c2d44dad..86c4241a0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -37,7 +37,7 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -50,6 +50,7 @@ result = new MyTestId(res); return ok; } +#nullable disable public class EfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt index 1694a026b..2a5fd2656 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -33,7 +33,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -46,5 +46,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt index 1694a026b..2a5fd2656 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -33,7 +33,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -46,5 +46,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt index 1694a026b..2a5fd2656 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -33,7 +33,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -46,5 +46,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt index 1694a026b..2a5fd2656 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -33,7 +33,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -46,5 +46,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index 1694a026b..2a5fd2656 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -33,7 +33,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(Guid.Parse(s)); @@ -46,5 +46,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt index 5abfad40b..237765cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt index 5abfad40b..237765cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt index 5abfad40b..237765cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt index 5abfad40b..237765cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index 5abfad40b..237765cb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(int.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt index 4acb87d6f..02dd6ea27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt index 4acb87d6f..02dd6ea27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt index 4acb87d6f..02dd6ea27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt index 4acb87d6f..02dd6ea27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 4acb87d6f..02dd6ea27 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -32,7 +32,7 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); - +#nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { return new MyTestId(long.Parse(s)); @@ -45,5 +45,6 @@ result = new MyTestId(res); return ok; } +#nullable disable } diff --git a/version.props b/version.props index 39cee7c3d..05bc4a48a 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.16 + 1.0.17 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From ee4073f5e49310be2423fc2005c1c70fcdd271e9 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Tue, 14 Mar 2023 14:22:49 +0300 Subject: [PATCH 36/37] DapperTypeHandler Init/DbType --- .../Templates/Guid/Guid_DapperTypeHandler.cs | 11 ++++++++++- .../Templates/Guid/Guid_Parsable.cs | 7 ++++--- .../Templates/Int/Int_DapperTypeHandler.cs | 12 +++++++++++- .../Templates/Int/Int_Parsable.cs | 7 ++++--- .../Templates/Long/Long_DapperTypeHandler.cs | 9 +++++++++ .../Templates/Long/Long_Parsable.cs | 7 ++++--- .../Templates/NewId/NewId_DapperTypeHandler.cs | 10 +++++++++- .../Templates/NewId/NewId_Parsable.cs | 7 +++++-- .../NullableString_DapperTypeHandler.cs | 11 ++++++++++- .../NullableString/NullableString_Parsable.cs | 5 +++-- .../Templates/String/String_DapperTypeHandler.cs | 11 ++++++++++- .../Templates/String/String_Parsable.cs | 3 ++- .../StronglyTypedIds.IntegrationTests.csproj | 5 +++++ ...ullIdCorrectly_type=Guid.Core3_1.verified.txt | 15 +++++++++++++-- ...lIdCorrectly_type=Guid.DotNet6_0.verified.txt | 15 +++++++++++++-- ...lIdCorrectly_type=Guid.DotNet7_0.verified.txt | 15 +++++++++++++-- ...FullIdCorrectly_type=Guid.Net4_8.verified.txt | 15 +++++++++++++-- ...neratesFullIdCorrectly_type=Guid.verified.txt | 15 +++++++++++++-- ...FullIdCorrectly_type=Int.Core3_1.verified.txt | 16 ++++++++++++++-- ...llIdCorrectly_type=Int.DotNet6_0.verified.txt | 16 ++++++++++++++-- ...llIdCorrectly_type=Int.DotNet7_0.verified.txt | 16 ++++++++++++++-- ...sFullIdCorrectly_type=Int.Net4_8.verified.txt | 16 ++++++++++++++-- ...eneratesFullIdCorrectly_type=Int.verified.txt | 16 ++++++++++++++-- ...ullIdCorrectly_type=Long.Core3_1.verified.txt | 14 ++++++++++++-- ...lIdCorrectly_type=Long.DotNet6_0.verified.txt | 14 ++++++++++++-- ...lIdCorrectly_type=Long.DotNet7_0.verified.txt | 14 ++++++++++++-- ...FullIdCorrectly_type=Long.Net4_8.verified.txt | 14 ++++++++++++-- ...neratesFullIdCorrectly_type=Long.verified.txt | 14 ++++++++++++-- ...ly_type=MassTransitNewId.Core3_1.verified.txt | 16 ++++++++++++++-- ..._type=MassTransitNewId.DotNet6_0.verified.txt | 16 ++++++++++++++-- ..._type=MassTransitNewId.DotNet7_0.verified.txt | 16 ++++++++++++++-- ...tly_type=MassTransitNewId.Net4_8.verified.txt | 16 ++++++++++++++-- ...dCorrectly_type=MassTransitNewId.verified.txt | 16 ++++++++++++++-- ...ctly_type=NullableString.Core3_1.verified.txt | 15 +++++++++++++-- ...ly_type=NullableString.DotNet6_0.verified.txt | 15 +++++++++++++-- ...ly_type=NullableString.DotNet7_0.verified.txt | 15 +++++++++++++-- ...ectly_type=NullableString.Net4_8.verified.txt | 15 +++++++++++++-- ...lIdCorrectly_type=NullableString.verified.txt | 15 +++++++++++++-- ...lIdCorrectly_type=String.Core3_1.verified.txt | 13 ++++++++++++- ...dCorrectly_type=String.DotNet6_0.verified.txt | 13 ++++++++++++- ...dCorrectly_type=String.DotNet7_0.verified.txt | 13 ++++++++++++- ...llIdCorrectly_type=String.Net4_8.verified.txt | 13 ++++++++++++- ...ratesFullIdCorrectly_type=String.verified.txt | 13 ++++++++++++- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 10 ++++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 10 ++++++++++ ...=Guid_c=DapperTypeHandler_i=None.verified.txt | 10 ++++++++++ ...=Guid_c=None_i=IParsable.Core3_1.verified.txt | 5 +++-- ...uid_c=None_i=IParsable.DotNet6_0.verified.txt | 5 +++-- ...uid_c=None_i=IParsable.DotNet7_0.verified.txt | 5 +++-- ...e=Guid_c=None_i=IParsable.Net4_8.verified.txt | 5 +++-- ...tly_type=Guid_c=None_i=IParsable.verified.txt | 5 +++-- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 11 +++++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 11 +++++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 11 +++++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 11 +++++++++++ ...e=Int_c=DapperTypeHandler_i=None.verified.txt | 11 +++++++++++ ...e=Int_c=None_i=IParsable.Core3_1.verified.txt | 5 +++-- ...Int_c=None_i=IParsable.DotNet6_0.verified.txt | 5 +++-- ...Int_c=None_i=IParsable.DotNet7_0.verified.txt | 5 +++-- ...pe=Int_c=None_i=IParsable.Net4_8.verified.txt | 5 +++-- ...ctly_type=Int_c=None_i=IParsable.verified.txt | 5 +++-- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 9 +++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 9 +++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 9 +++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 9 +++++++++ ...=Long_c=DapperTypeHandler_i=None.verified.txt | 9 +++++++++ ...=Long_c=None_i=IParsable.Core3_1.verified.txt | 5 +++-- ...ong_c=None_i=IParsable.DotNet6_0.verified.txt | 5 +++-- ...ong_c=None_i=IParsable.DotNet7_0.verified.txt | 5 +++-- ...e=Long_c=None_i=IParsable.Net4_8.verified.txt | 5 +++-- ...tly_type=Long_c=None_i=IParsable.verified.txt | 5 +++-- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 9 +++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 9 +++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 9 +++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 9 +++++++++ ...NewId_c=DapperTypeHandler_i=None.verified.txt | 9 +++++++++ ...NewId_c=None_i=IParsable.Core3_1.verified.txt | 7 +++++-- ...wId_c=None_i=IParsable.DotNet6_0.verified.txt | 7 +++++-- ...wId_c=None_i=IParsable.DotNet7_0.verified.txt | 7 +++++-- ...tNewId_c=None_i=IParsable.Net4_8.verified.txt | 7 +++++-- ...sTransitNewId_c=None_i=IParsable.verified.txt | 7 +++++-- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 10 ++++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 10 ++++++++++ ...tring_c=DapperTypeHandler_i=None.verified.txt | 10 ++++++++++ ...tring_c=None_i=IParsable.Core3_1.verified.txt | 5 +++-- ...ing_c=None_i=IParsable.DotNet6_0.verified.txt | 5 +++-- ...ing_c=None_i=IParsable.DotNet7_0.verified.txt | 5 +++-- ...String_c=None_i=IParsable.Net4_8.verified.txt | 5 +++-- ...ullableString_c=None_i=IParsable.verified.txt | 5 +++-- ...DapperTypeHandler_i=None.Core3_1.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet6_0.verified.txt | 10 ++++++++++ ...pperTypeHandler_i=None.DotNet7_0.verified.txt | 10 ++++++++++ ...=DapperTypeHandler_i=None.Net4_8.verified.txt | 10 ++++++++++ ...tring_c=DapperTypeHandler_i=None.verified.txt | 10 ++++++++++ ...tring_c=None_i=IParsable.Core3_1.verified.txt | 3 ++- ...ing_c=None_i=IParsable.DotNet6_0.verified.txt | 3 ++- ...ing_c=None_i=IParsable.DotNet7_0.verified.txt | 3 ++- ...String_c=None_i=IParsable.Net4_8.verified.txt | 3 ++- ...y_type=String_c=None_i=IParsable.verified.txt | 3 ++- version.props | 2 +- 104 files changed, 867 insertions(+), 130 deletions(-) diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Guid/Guid_DapperTypeHandler.cs index 7d94a235e..7b48c73b1 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_DapperTypeHandler.cs @@ -4,6 +4,7 @@ public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler public override void SetValue(System.Data.IDbDataParameter parameter, TESTID value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override TESTID Parse(object value) @@ -15,4 +16,12 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + + } diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs index f05831196..85f7095a7 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Parsable.cs @@ -1,13 +1,14 @@ -#nullable enable + +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { - return new TESTID(Guid.Parse(s)); + return new TESTID(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new TESTID(res); return ok; } diff --git a/src/StronglyTypedIds/Templates/Int/Int_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Int/Int_DapperTypeHandler.cs index 8e3dc42c9..2da54911b 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_DapperTypeHandler.cs @@ -4,6 +4,7 @@ public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler public override void SetValue(System.Data.IDbDataParameter parameter, TESTID value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override TESTID Parse(object value) @@ -16,4 +17,13 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + + } diff --git a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs index 2632b7145..f5893b0ca 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_Parsable.cs @@ -1,13 +1,14 @@ -#nullable enable + +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { - return new TESTID(int.Parse(s)); + return new TESTID(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new TESTID(res); return ok; } diff --git a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs index eb6441ac7..e8f11b11c 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_DapperTypeHandler.cs @@ -4,6 +4,7 @@ public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler public override void SetValue(System.Data.IDbDataParameter parameter, TESTID value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override TESTID Parse(object value) @@ -18,4 +19,12 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs index be4cbe4a4..3a63073f9 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_Parsable.cs @@ -1,13 +1,14 @@ -#nullable enable + +#nullable enable public static TESTID Parse(string s, System.IFormatProvider? provider) { - return new TESTID(long.Parse(s)); + return new TESTID(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out TESTID result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new TESTID(res); return ok; } diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/NewId/NewId_DapperTypeHandler.cs index 8d4af7b02..04e3693b5 100644 --- a/src/StronglyTypedIds/Templates/NewId/NewId_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/NewId/NewId_DapperTypeHandler.cs @@ -15,4 +15,12 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs b/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs index d205c674e..2faf43e0d 100644 --- a/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs +++ b/src/StronglyTypedIds/Templates/NewId/NewId_Parsable.cs @@ -1,10 +1,13 @@  public static TESTID Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new TESTID(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new TESTID(res); + return ok; } diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_DapperTypeHandler.cs index 1524a13b1..91720bcc8 100644 --- a/src/StronglyTypedIds/Templates/NullableString/NullableString_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_DapperTypeHandler.cs @@ -4,6 +4,7 @@ public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler public override void SetValue(System.Data.IDbDataParameter parameter, TESTID value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override TESTID Parse(object value) @@ -16,4 +17,12 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs index d205c674e..1cd9b15e1 100644 --- a/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs +++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_Parsable.cs @@ -1,10 +1,11 @@  public static TESTID Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new TESTID(s); } public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + result = new TESTID(s); + return true; } diff --git a/src/StronglyTypedIds/Templates/String/String_DapperTypeHandler.cs b/src/StronglyTypedIds/Templates/String/String_DapperTypeHandler.cs index 93d6ff7bf..9b0f11bc6 100644 --- a/src/StronglyTypedIds/Templates/String/String_DapperTypeHandler.cs +++ b/src/StronglyTypedIds/Templates/String/String_DapperTypeHandler.cs @@ -4,6 +4,7 @@ public class DapperTypeHandler : Dapper.SqlMapper.TypeHandler public override void SetValue(System.Data.IDbDataParameter parameter, TESTID value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override TESTID Parse(object value) @@ -14,4 +15,12 @@ public override TESTID Parse(object value) _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to TESTID"), }; } - } \ No newline at end of file + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } diff --git a/src/StronglyTypedIds/Templates/String/String_Parsable.cs b/src/StronglyTypedIds/Templates/String/String_Parsable.cs index d205c674e..769bd1bb2 100644 --- a/src/StronglyTypedIds/Templates/String/String_Parsable.cs +++ b/src/StronglyTypedIds/Templates/String/String_Parsable.cs @@ -6,5 +6,6 @@ public static TESTID Parse(string s, IFormatProvider? provider) public static bool TryParse(string? s, IFormatProvider? provider, out TESTID result) { - throw new NotImplementedException(); + result = new TESTID(s); + return true; } diff --git a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj index 6c9961413..178bffc70 100644 --- a/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj +++ b/test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj @@ -12,6 +12,11 @@ + + + + + diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 04e282a91..4ff4510cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -38,16 +38,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -70,6 +71,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -81,8 +83,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt index 04e282a91..4ff4510cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -38,16 +38,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -70,6 +71,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -81,8 +83,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 04e282a91..4ff4510cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -38,16 +38,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -70,6 +71,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -81,8 +83,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt index 04e282a91..4ff4510cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -38,16 +38,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -70,6 +71,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -81,8 +83,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 04e282a91..4ff4510cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -38,16 +38,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -70,6 +71,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -81,8 +83,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index 5f076338a..78dbd94f7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -81,8 +83,18 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt index 5f076338a..78dbd94f7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -81,8 +83,18 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 5f076338a..78dbd94f7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -81,8 +83,18 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt index 5f076338a..78dbd94f7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -81,8 +83,18 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index 5f076338a..78dbd94f7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -81,8 +83,18 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index 86c4241a0..c8f5507a2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -83,6 +85,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt index 86c4241a0..c8f5507a2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -83,6 +85,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index 86c4241a0..c8f5507a2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -83,6 +85,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt index 86c4241a0..c8f5507a2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -83,6 +85,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index 86c4241a0..c8f5507a2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -37,16 +37,17 @@ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); public int CompareTo(MyTestId other) => Value.CompareTo(other.Value); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } @@ -69,6 +70,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -83,6 +85,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt index c3f1cc375..c1043b288 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -41,12 +41,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } @@ -77,8 +80,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt index c3f1cc375..c1043b288 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -41,12 +41,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } @@ -77,8 +80,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index c3f1cc375..c1043b288 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -41,12 +41,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } @@ -77,8 +80,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt index c3f1cc375..c1043b288 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -41,12 +41,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } @@ -77,8 +80,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index c3f1cc375..c1043b288 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -41,12 +41,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } @@ -77,8 +80,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt index f19a52499..0ba9eeb7d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -58,12 +58,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -95,8 +97,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt index f19a52499..0ba9eeb7d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -58,12 +58,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -95,8 +97,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index f19a52499..0ba9eeb7d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -58,12 +58,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -95,8 +97,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt index f19a52499..0ba9eeb7d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -58,12 +58,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -95,8 +97,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index f19a52499..0ba9eeb7d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -58,12 +58,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -95,8 +97,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt index 151f2796e..d4f5ed091 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -63,7 +63,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -93,8 +95,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt index 151f2796e..d4f5ed091 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -63,7 +63,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -93,8 +95,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index 151f2796e..d4f5ed091 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -63,7 +63,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -93,8 +95,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt index 151f2796e..d4f5ed091 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -63,7 +63,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -93,8 +95,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index 151f2796e..d4f5ed091 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -63,7 +63,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } @@ -83,6 +84,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -93,8 +95,17 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + class MyTestIdTypeConverter : System.ComponentModel.TypeConverter { public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt index bb6b344ab..c7965c54d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -39,6 +39,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -50,5 +51,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index bb6b344ab..c7965c54d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -39,6 +39,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -50,5 +51,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index bb6b344ab..c7965c54d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -39,6 +39,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -50,5 +51,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt index bb6b344ab..c7965c54d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -39,6 +39,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -50,5 +51,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt index bb6b344ab..c7965c54d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt @@ -39,6 +39,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Guid; } public override MyTestId Parse(object value) @@ -50,5 +51,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt index 2a5fd2656..e94e1a2ac 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -33,16 +33,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt index 2a5fd2656..e94e1a2ac 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -33,16 +33,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt index 2a5fd2656..e94e1a2ac 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -33,16 +33,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt index 2a5fd2656..e94e1a2ac 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -33,16 +33,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index 2a5fd2656..e94e1a2ac 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -33,16 +33,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(Guid.Parse(s)); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = Guid.TryParse(s, out res); + var ok = Guid.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt index f8d24bbf5..5ed784d4a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -50,5 +51,15 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index f8d24bbf5..5ed784d4a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -50,5 +51,15 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index f8d24bbf5..5ed784d4a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -50,5 +51,15 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt index f8d24bbf5..5ed784d4a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -50,5 +51,15 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt index f8d24bbf5..5ed784d4a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int32; } public override MyTestId Parse(object value) @@ -50,5 +51,15 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 + } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt index 237765cb9..48b56d13e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt index 237765cb9..48b56d13e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt index 237765cb9..48b56d13e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt index 237765cb9..48b56d13e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index 237765cb9..48b56d13e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(int.Parse(s)); + return new MyTestId(int.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { int res = 0; - var ok = int.TryParse(s, out res); + var ok = int.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 1f4769435..b62d70add 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -52,6 +53,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 1f4769435..b62d70add 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -52,6 +53,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 1f4769435..b62d70add 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -52,6 +53,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 1f4769435..b62d70add 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -52,6 +53,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt index 1f4769435..b62d70add 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt @@ -38,6 +38,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.Int64; } public override MyTestId Parse(object value) @@ -52,6 +53,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt index 02dd6ea27..45dac2ba8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt index 02dd6ea27..45dac2ba8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt index 02dd6ea27..45dac2ba8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt index 02dd6ea27..45dac2ba8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 02dd6ea27..45dac2ba8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -32,16 +32,17 @@ public override string ToString() => Value.ToString(); public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b); public static bool operator !=(MyTestId a, MyTestId b) => !(a == b); + #nullable enable public static MyTestId Parse(string s, System.IFormatProvider? provider) { - return new MyTestId(long.Parse(s)); + return new MyTestId(long.Parse(s, provider)); } public static bool TryParse(string? s, System.IFormatProvider? provider, out MyTestId result) { long res = 0; - var ok = long.TryParse(s, out res); + var ok = long.TryParse(s, provider, out res); result = new MyTestId(res); return ok; } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 23efe4b09..6b5b8702d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -50,5 +50,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 23efe4b09..6b5b8702d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -50,5 +50,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 23efe4b09..6b5b8702d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -50,5 +50,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 23efe4b09..6b5b8702d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -50,5 +50,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt index 23efe4b09..6b5b8702d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt @@ -50,5 +50,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt index ce7836cb8..f71234e03 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt @@ -36,12 +36,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt index ce7836cb8..f71234e03 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt @@ -36,12 +36,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt index ce7836cb8..f71234e03 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt @@ -36,12 +36,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt index ce7836cb8..f71234e03 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt @@ -36,12 +36,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index ce7836cb8..f71234e03 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -36,12 +36,15 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(Guid.Parse(s, provider)); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + long res = 0; + var ok = Guid.TryParse(s, provider, out res); + result = new MyTestId(res); + return ok; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt index c96f1e168..158253dea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -59,5 +60,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index c96f1e168..158253dea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -59,5 +60,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index c96f1e168..158253dea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -59,5 +60,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt index c96f1e168..158253dea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -59,5 +60,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt index c96f1e168..158253dea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -59,5 +60,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt index f665bb078..cb8f66e2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt @@ -44,12 +44,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt index f665bb078..cb8f66e2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt @@ -44,12 +44,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt index f665bb078..cb8f66e2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt @@ -44,12 +44,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt index f665bb078..cb8f66e2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt @@ -44,12 +44,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index f665bb078..cb8f66e2d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -44,12 +44,13 @@ public static MyTestId Parse(string s, IFormatProvider? provider) { - throw new NotImplementedException(); + return new MyTestId(s); } public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 749dd1dbd..80f82650a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -57,5 +58,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 749dd1dbd..80f82650a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -57,5 +58,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 749dd1dbd..80f82650a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -57,5 +58,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 749dd1dbd..80f82650a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -57,5 +58,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt index 749dd1dbd..80f82650a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt @@ -47,6 +47,7 @@ public override void SetValue(System.Data.IDbDataParameter parameter, MyTestId value) { parameter.Value = value.Value; + parameter.DbType = System.Data.DbType.AnsiString; } public override MyTestId Parse(object value) @@ -57,5 +58,14 @@ _ => throw new System.InvalidCastException($"Unable to cast object of type {value.GetType()} to MyTestId"), }; } + +#pragma warning disable CA2255 + [System.Runtime.CompilerServices.ModuleInitializerAttribute] + public static void AddTypeHandler() + { + Dapper.SqlMapper.AddTypeHandler(new DapperTypeHandler()); + } +#pragma warning restore CA2255 } + } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt index 99577f35a..ea5cbe4e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt @@ -49,7 +49,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt index 99577f35a..ea5cbe4e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt @@ -49,7 +49,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt index 99577f35a..ea5cbe4e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt @@ -49,7 +49,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt index 99577f35a..ea5cbe4e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt @@ -49,7 +49,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index 99577f35a..ea5cbe4e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -49,7 +49,8 @@ public static bool TryParse(string? s, IFormatProvider? provider, out MyTestId result) { - throw new NotImplementedException(); + result = new MyTestId(s); + return true; } } diff --git a/version.props b/version.props index 05bc4a48a..ee9424be0 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.17 + 1.0.18 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix) From c71beb099178555eee5bb0f4bf0c1cdfab251701 Mon Sep 17 00:00:00 2001 From: Konstantin Gonsovsky Date: Thu, 16 Mar 2023 14:26:02 +0300 Subject: [PATCH 37/37] DefaultConstructor --- src/StronglyTypedIds/Templates/Guid/Guid_Base.cs | 4 ++++ src/StronglyTypedIds/Templates/Int/Int_Base.cs | 4 ++++ src/StronglyTypedIds/Templates/Long/Long_Base.cs | 4 ++++ src/StronglyTypedIds/Templates/NewId/NewId_Base.cs | 4 ++++ .../Templates/NullableString/NullableString_Base.cs | 4 ++++ src/StronglyTypedIds/Templates/String/String_Base.cs | 4 ++++ ...eneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt | 4 ++++ ...GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt | 4 ++++ ...tTests.GeneratesFullIdCorrectly_type=Guid.verified.txt | 4 ++++ ...GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt | 4 ++++ ...neratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt | 4 ++++ ...neratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt | 4 ++++ ....GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt | 4 ++++ ...otTests.GeneratesFullIdCorrectly_type=Int.verified.txt | 4 ++++ ...eneratesFullIdCorrectly_type=Long.Core3_1.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt | 4 ++++ ...GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt | 4 ++++ ...tTests.GeneratesFullIdCorrectly_type=Long.verified.txt | 4 ++++ ...IdCorrectly_type=MassTransitNewId.Core3_1.verified.txt | 4 ++++ ...Correctly_type=MassTransitNewId.DotNet6_0.verified.txt | 4 ++++ ...Correctly_type=MassTransitNewId.DotNet7_0.verified.txt | 4 ++++ ...lIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt | 4 ++++ ...atesFullIdCorrectly_type=MassTransitNewId.verified.txt | 4 ++++ ...llIdCorrectly_type=NullableString.Core3_1.verified.txt | 4 ++++ ...IdCorrectly_type=NullableString.DotNet6_0.verified.txt | 4 ++++ ...IdCorrectly_type=NullableString.DotNet7_0.verified.txt | 4 ++++ ...ullIdCorrectly_type=NullableString.Net4_8.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=NullableString.verified.txt | 4 ++++ ...eratesFullIdCorrectly_type=String.Core3_1.verified.txt | 4 ++++ ...atesFullIdCorrectly_type=String.DotNet6_0.verified.txt | 4 ++++ ...atesFullIdCorrectly_type=String.DotNet7_0.verified.txt | 4 ++++ ...neratesFullIdCorrectly_type=String.Net4_8.verified.txt | 4 ++++ ...ests.GeneratesFullIdCorrectly_type=String.verified.txt | 4 ++++ ...e=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...pe=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...ctly_type=Guid_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...uid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...d_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...d_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...y_type=Guid_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ...type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...pe=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...pe=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ..._type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...rrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ...ly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ..._type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ..._type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...tly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ...dCorrectly_type=Guid_c=None_i=IComparable.verified.txt | 4 ++++ ...tly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...y_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...y_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...ctly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...IdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt | 4 ++++ ...ctly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ...ly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ...ly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...ectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ...sIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt | 4 ++++ ...Correctly_type=Guid_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...rrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...rrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ...dCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...eratesIdCorrectly_type=Guid_c=None_i=None.verified.txt | 4 ++++ ...Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...id_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...id_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ...ly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ...type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...pe=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...pe=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ..._type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...rrectly_type=Guid_c=SystemTextJson_i=None.verified.txt | 4 ++++ ..._type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...ype=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...ype=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...y_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...orrectly_type=Guid_c=TypeConverter_i=None.verified.txt | 4 ++++ ...pe=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...ype=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...ectly_type=Int_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...t_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...t_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...ly_type=Int_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ..._type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...ype=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...ype=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...y_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...orrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ...tly_type=Int_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ...y_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ...y_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...ctly_type=Int_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ...IdCorrectly_type=Int_c=None_i=IComparable.verified.txt | 4 ++++ ...ctly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...ly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...ly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...ectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...sIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt | 4 ++++ ...ectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ...tly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ...tly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...rectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ...esIdCorrectly_type=Int_c=None_i=IParsable.verified.txt | 4 ++++ ...dCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...orrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...orrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ...IdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...neratesIdCorrectly_type=Int_c=None_i=None.verified.txt | 4 ++++ ...=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...nt_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...nt_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...e=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ...tly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ..._type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...ype=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...ype=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...y_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...orrectly_type=Int_c=SystemTextJson_i=None.verified.txt | 4 ++++ ...y_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...ly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...Correctly_type=Int_c=TypeConverter_i=None.verified.txt | 4 ++++ ...e=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...pe=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...ctly_type=Long_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...ong_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...y_type=Long_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ...type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...pe=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...pe=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ..._type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...rrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ...ly_type=Long_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ..._type=Long_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ..._type=Long_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...tly_type=Long_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ...dCorrectly_type=Long_c=None_i=IComparable.verified.txt | 4 ++++ ...tly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...y_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...y_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...ctly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...IdCorrectly_type=Long_c=None_i=IEquatable.verified.txt | 4 ++++ ...ctly_type=Long_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ...ly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ...ly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...ectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ...sIdCorrectly_type=Long_c=None_i=IParsable.verified.txt | 4 ++++ ...Correctly_type=Long_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...rrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...rrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ...dCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...eratesIdCorrectly_type=Long_c=None_i=None.verified.txt | 4 ++++ ...Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ...ly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ...type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...pe=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...pe=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ..._type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...rrectly_type=Long_c=SystemTextJson_i=None.verified.txt | 4 ++++ ..._type=Long_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...ype=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...ype=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...y_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...orrectly_type=Long_c=TypeConverter_i=None.verified.txt | 4 ++++ ...tNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...ewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...ewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...itNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...ssTransitNewId_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...wId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...d_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...d_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...ewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...ransitNewId_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ...nsitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...itNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...itNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ansitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ...TransitNewId_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ...ansitNewId_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ...ansitNewId_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...sTransitNewId_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ...ype=MassTransitNewId_c=None_i=IComparable.verified.txt | 4 ++++ ...sTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...ransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...ransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...ssTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...type=MassTransitNewId_c=None_i=IEquatable.verified.txt | 4 ++++ ...ssTransitNewId_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ...TransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ...TransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...assTransitNewId_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ..._type=MassTransitNewId_c=None_i=IParsable.verified.txt | 4 ++++ ...pe=MassTransitNewId_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ...ype=MassTransitNewId_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...ectly_type=MassTransitNewId_c=None_i=None.verified.txt | 4 ++++ ...ewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...Id_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...Id_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...NewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ...TransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ...nsitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...itNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...itNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ansitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...=MassTransitNewId_c=SystemTextJson_i=None.verified.txt | 4 ++++ ...ansitNewId_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...sitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...sitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...ransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...e=MassTransitNewId_c=TypeConverter_i=None.verified.txt | 4 ++++ ...String_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...ring_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...ring_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...eString_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...NullableString_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...ing_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...ring_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...lableString_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ...bleString_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...eString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...eString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...pe=NullableString_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ...llableString_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ...ableString_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ...ableString_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...ullableString_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ..._type=NullableString_c=None_i=IComparable.verified.txt | 4 ++++ ...ullableString_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...lableString_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...lableString_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...NullableString_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...y_type=NullableString_c=None_i=IEquatable.verified.txt | 4 ++++ ...NullableString_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ...llableString_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ...llableString_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...=NullableString_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ...ly_type=NullableString_c=None_i=IParsable.verified.txt | 4 ++++ ...type=NullableString_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...pe=NullableString_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...pe=NullableString_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ..._type=NullableString_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...rrectly_type=NullableString_c=None_i=None.verified.txt | 4 ++++ ...ring_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...tring_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ...llableString_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ...bleString_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...eString_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...eString_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ableString_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...pe=NullableString_c=SystemTextJson_i=None.verified.txt | 4 ++++ ...ableString_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...leString_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...leString_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...lableString_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...ype=NullableString_c=TypeConverter_i=None.verified.txt | 4 ++++ ...String_c=DapperTypeHandler_i=None.Core3_1.verified.txt | 4 ++++ ...ring_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt | 4 ++++ ...ring_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt | 4 ++++ ...=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt | 4 ++++ ...ly_type=String_c=DapperTypeHandler_i=None.verified.txt | 4 ++++ ...ing_c=EfCoreValueConverter_i=None.Core3_1.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...g_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...ring_c=EfCoreValueConverter_i=None.Net4_8.verified.txt | 4 ++++ ...type=String_c=EfCoreValueConverter_i=None.verified.txt | 4 ++++ ...pe=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt | 4 ++++ ...=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ype=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt | 4 ++++ ...ectly_type=String_c=NewtonsoftJson_i=None.verified.txt | 4 ++++ ..._type=String_c=None_i=IComparable.Core3_1.verified.txt | 4 ++++ ...ype=String_c=None_i=IComparable.DotNet6_0.verified.txt | 4 ++++ ...ype=String_c=None_i=IComparable.DotNet7_0.verified.txt | 4 ++++ ...y_type=String_c=None_i=IComparable.Net4_8.verified.txt | 4 ++++ ...orrectly_type=String_c=None_i=IComparable.verified.txt | 4 ++++ ...y_type=String_c=None_i=IEquatable.Core3_1.verified.txt | 4 ++++ ...type=String_c=None_i=IEquatable.DotNet6_0.verified.txt | 4 ++++ ...type=String_c=None_i=IEquatable.DotNet7_0.verified.txt | 4 ++++ ...ly_type=String_c=None_i=IEquatable.Net4_8.verified.txt | 4 ++++ ...Correctly_type=String_c=None_i=IEquatable.verified.txt | 4 ++++ ...ly_type=String_c=None_i=IParsable.Core3_1.verified.txt | 4 ++++ ..._type=String_c=None_i=IParsable.DotNet6_0.verified.txt | 4 ++++ ..._type=String_c=None_i=IParsable.DotNet7_0.verified.txt | 4 ++++ ...tly_type=String_c=None_i=IParsable.Net4_8.verified.txt | 4 ++++ ...dCorrectly_type=String_c=None_i=IParsable.verified.txt | 4 ++++ ...rrectly_type=String_c=None_i=None.Core3_1.verified.txt | 4 ++++ ...ectly_type=String_c=None_i=None.DotNet6_0.verified.txt | 4 ++++ ...ectly_type=String_c=None_i=None.DotNet7_0.verified.txt | 4 ++++ ...orrectly_type=String_c=None_i=None.Net4_8.verified.txt | 4 ++++ ...atesIdCorrectly_type=String_c=None_i=None.verified.txt | 4 ++++ ...ring_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt | 4 ++++ ...ng_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt | 4 ++++ ...tring_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt | 4 ++++ ..._type=String_c=SwaggerSchemaFilter_i=None.verified.txt | 4 ++++ ...pe=String_c=SystemTextJson_i=None.Core3_1.verified.txt | 4 ++++ ...=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt | 4 ++++ ...=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt | 4 ++++ ...ype=String_c=SystemTextJson_i=None.Net4_8.verified.txt | 4 ++++ ...ectly_type=String_c=SystemTextJson_i=None.verified.txt | 4 ++++ ...ype=String_c=TypeConverter_i=None.Core3_1.verified.txt | 4 ++++ ...e=String_c=TypeConverter_i=None.DotNet6_0.verified.txt | 4 ++++ ...e=String_c=TypeConverter_i=None.DotNet7_0.verified.txt | 4 ++++ ...type=String_c=TypeConverter_i=None.Net4_8.verified.txt | 4 ++++ ...rectly_type=String_c=TypeConverter_i=None.verified.txt | 4 ++++ ...ClassCorrectly_nestedClassCount=0.Core3_1.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=0.DotNet6_0.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=0.DotNet7_0.verified.txt | 4 ++++ ...dClassCorrectly_nestedClassCount=0.Net4_8.verified.txt | 4 ++++ ...thNestedClassCorrectly_nestedClassCount=0.verified.txt | 4 ++++ ...ClassCorrectly_nestedClassCount=1.Core3_1.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=1.DotNet6_0.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=1.DotNet7_0.verified.txt | 4 ++++ ...dClassCorrectly_nestedClassCount=1.Net4_8.verified.txt | 4 ++++ ...thNestedClassCorrectly_nestedClassCount=1.verified.txt | 4 ++++ ...ClassCorrectly_nestedClassCount=2.Core3_1.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=2.DotNet6_0.verified.txt | 4 ++++ ...assCorrectly_nestedClassCount=2.DotNet7_0.verified.txt | 4 ++++ ...dClassCorrectly_nestedClassCount=2.Net4_8.verified.txt | 4 ++++ ...thNestedClassCorrectly_nestedClassCount=2.verified.txt | 4 ++++ ...enerateDefaultIdInGlobalNamespace.Core3_1.verified.txt | 4 ++++ ...erateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt | 4 ++++ ...erateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt | 4 ++++ ...GenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt | 4 ++++ ...sts.CanGenerateDefaultIdInGlobalNamespace.verified.txt | 4 ++++ ...anGenerateIdInFileScopedNamespace.Core3_1.verified.txt | 4 ++++ ...GenerateIdInFileScopedNamespace.DotNet6_0.verified.txt | 4 ++++ ...GenerateIdInFileScopedNamespace.DotNet7_0.verified.txt | 4 ++++ ...CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt | 4 ++++ ...rTests.CanGenerateIdInFileScopedNamespace.verified.txt | 4 ++++ ...torTests.CanGenerateIdInNamespace.Core3_1.verified.txt | 4 ++++ ...rTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt | 4 ++++ ...rTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt | 4 ++++ ...atorTests.CanGenerateIdInNamespace.Net4_8.verified.txt | 4 ++++ ...IdGeneratorTests.CanGenerateIdInNamespace.verified.txt | 4 ++++ ...er=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt | 4 ++++ ...=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt | 4 ++++ ...=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt | 4 ++++ ...ter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt | 4 ++++ ..._converter=NewtonsoftJson, SystemTextJson.verified.txt | 4 ++++ ...ype=Guid_converter=NewtonsoftJson.Core3_1.verified.txt | 4 ++++ ...e=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt | 4 ++++ ...e=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt | 4 ++++ ...Type=Guid_converter=NewtonsoftJson.Net4_8.verified.txt | 4 ++++ ...backingType=Guid_converter=NewtonsoftJson.verified.txt | 4 ++++ ...ype=Guid_converter=SystemTextJson.Core3_1.verified.txt | 4 ++++ ...e=Guid_converter=SystemTextJson.DotNet6_0.verified.txt | 4 ++++ ...e=Guid_converter=SystemTextJson.DotNet7_0.verified.txt | 4 ++++ ...Type=Guid_converter=SystemTextJson.Net4_8.verified.txt | 4 ++++ ...backingType=Guid_converter=SystemTextJson.verified.txt | 4 ++++ ...Type=Guid_converter=TypeConverter.Core3_1.verified.txt | 4 ++++ ...pe=Guid_converter=TypeConverter.DotNet6_0.verified.txt | 4 ++++ ...pe=Guid_converter=TypeConverter.DotNet7_0.verified.txt | 4 ++++ ...gType=Guid_converter=TypeConverter.Net4_8.verified.txt | 4 ++++ ..._backingType=Guid_converter=TypeConverter.verified.txt | 4 ++++ ...s_backingType=Guid_converter=null.Core3_1.verified.txt | 4 ++++ ...backingType=Guid_converter=null.DotNet6_0.verified.txt | 4 ++++ ...backingType=Guid_converter=null.DotNet7_0.verified.txt | 4 ++++ ...rs_backingType=Guid_converter=null.Net4_8.verified.txt | 4 ++++ ...arameters_backingType=Guid_converter=null.verified.txt | 4 ++++ ...er=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt | 4 ++++ ...=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt | 4 ++++ ...=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt | 4 ++++ ...ter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt | 4 ++++ ..._converter=NewtonsoftJson, SystemTextJson.verified.txt | 4 ++++ ...ype=Guid_converter=NewtonsoftJson.Core3_1.verified.txt | 4 ++++ ...e=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt | 4 ++++ ...e=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt | 4 ++++ ...Type=Guid_converter=NewtonsoftJson.Net4_8.verified.txt | 4 ++++ ...backingType=Guid_converter=NewtonsoftJson.verified.txt | 4 ++++ ...ype=Guid_converter=SystemTextJson.Core3_1.verified.txt | 4 ++++ ...e=Guid_converter=SystemTextJson.DotNet6_0.verified.txt | 4 ++++ ...e=Guid_converter=SystemTextJson.DotNet7_0.verified.txt | 4 ++++ ...Type=Guid_converter=SystemTextJson.Net4_8.verified.txt | 4 ++++ ...backingType=Guid_converter=SystemTextJson.verified.txt | 4 ++++ ...Type=Guid_converter=TypeConverter.Core3_1.verified.txt | 4 ++++ ...pe=Guid_converter=TypeConverter.DotNet6_0.verified.txt | 4 ++++ ...pe=Guid_converter=TypeConverter.DotNet7_0.verified.txt | 4 ++++ ...gType=Guid_converter=TypeConverter.Net4_8.verified.txt | 4 ++++ ..._backingType=Guid_converter=TypeConverter.verified.txt | 4 ++++ ...s_backingType=Guid_converter=null.Core3_1.verified.txt | 4 ++++ ...backingType=Guid_converter=null.DotNet6_0.verified.txt | 4 ++++ ...backingType=Guid_converter=null.DotNet7_0.verified.txt | 4 ++++ ...rs_backingType=Guid_converter=null.Net4_8.verified.txt | 4 ++++ ...arameters_backingType=Guid_converter=null.verified.txt | 4 ++++ ...anGenerateMultipleIdsWithSameName.Core3_1.verified.txt | 8 ++++++++ ...GenerateMultipleIdsWithSameName.DotNet6_0.verified.txt | 8 ++++++++ ...GenerateMultipleIdsWithSameName.DotNet7_0.verified.txt | 8 ++++++++ ...CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt | 8 ++++++++ ...rTests.CanGenerateMultipleIdsWithSameName.verified.txt | 8 ++++++++ ...erateNestedIdInFileScopeNamespace.Core3_1.verified.txt | 4 ++++ ...ateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt | 4 ++++ ...ateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt | 4 ++++ ...nerateNestedIdInFileScopeNamespace.Net4_8.verified.txt | 4 ++++ ...s.CanGenerateNestedIdInFileScopeNamespace.verified.txt | 4 ++++ ...eVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt | 4 ++++ ...eryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt | 4 ++++ ...eryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt | 4 ++++ ...teVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt | 4 ++++ ...nGenerateVeryNestedIdInFileScopeNamespace.verified.txt | 4 ++++ ...rrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt | 4 ++++ ...ideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt | 4 ++++ ...ideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt | 4 ++++ ...errideDefaultsUsingGlobalAttribute.Net4_8.verified.txt | 4 ++++ ...s.CanOverrideDefaultsUsingGlobalAttribute.verified.txt | 4 ++++ version.props | 2 +- 437 files changed, 1765 insertions(+), 1 deletion(-) diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_Base.cs b/src/StronglyTypedIds/Templates/Guid/Guid_Base.cs index 200147a15..5f980f97a 100644 --- a/src/StronglyTypedIds/Templates/Guid/Guid_Base.cs +++ b/src/StronglyTypedIds/Templates/Guid/Guid_Base.cs @@ -7,6 +7,10 @@ public TESTID(System.Guid value) Value = value; } + public TESTID() + { + } + public static TESTID New() => new TESTID(System.Guid.NewGuid()); public static readonly TESTID Empty = new TESTID(System.Guid.Empty); diff --git a/src/StronglyTypedIds/Templates/Int/Int_Base.cs b/src/StronglyTypedIds/Templates/Int/Int_Base.cs index 08ce1fca6..04613630c 100644 --- a/src/StronglyTypedIds/Templates/Int/Int_Base.cs +++ b/src/StronglyTypedIds/Templates/Int/Int_Base.cs @@ -7,6 +7,10 @@ public TESTID(int value) Value = value; } + public TESTID() + { + } + public static readonly TESTID Empty = new TESTID(0); public bool Equals(TESTID other) => this.Value.Equals(other.Value); diff --git a/src/StronglyTypedIds/Templates/Long/Long_Base.cs b/src/StronglyTypedIds/Templates/Long/Long_Base.cs index 38d9fc5a6..77f7dd184 100644 --- a/src/StronglyTypedIds/Templates/Long/Long_Base.cs +++ b/src/StronglyTypedIds/Templates/Long/Long_Base.cs @@ -7,6 +7,10 @@ public TESTID(long value) Value = value; } + public TESTID() + { + } + public static readonly TESTID Empty = new TESTID(0); public bool Equals(TESTID other) => this.Value.Equals(other.Value); diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_Base.cs b/src/StronglyTypedIds/Templates/NewId/NewId_Base.cs index 854cd477a..4463479c2 100644 --- a/src/StronglyTypedIds/Templates/NewId/NewId_Base.cs +++ b/src/StronglyTypedIds/Templates/NewId/NewId_Base.cs @@ -7,6 +7,10 @@ public TESTID(MassTransit.NewId value) Value = value; } + public TESTID() + { + } + public static TESTID New() => new TESTID(MassTransit.NewId.Next()); public static readonly TESTID Empty = new TESTID(MassTransit.NewId.Empty); diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_Base.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_Base.cs index 94a6eaffb..3e7a28c12 100644 --- a/src/StronglyTypedIds/Templates/NullableString/NullableString_Base.cs +++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_Base.cs @@ -7,6 +7,10 @@ public TESTID(string? value) Value = value; } + public TESTID() + { + } + public static readonly TESTID Empty = new TESTID(string.Empty); public bool Equals(TESTID other) diff --git a/src/StronglyTypedIds/Templates/String/String_Base.cs b/src/StronglyTypedIds/Templates/String/String_Base.cs index 023df780b..8855711c6 100644 --- a/src/StronglyTypedIds/Templates/String/String_Base.cs +++ b/src/StronglyTypedIds/Templates/String/String_Base.cs @@ -7,6 +7,10 @@ public TESTID(string value) Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public TESTID() + { + } + public static readonly TESTID Empty = new TESTID(string.Empty); public bool Equals(TESTID other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt index 4ff4510cf..ed774067b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt index 4ff4510cf..ed774067b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt index 4ff4510cf..ed774067b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt index 4ff4510cf..ed774067b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Net4_8.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt index 4ff4510cf..ed774067b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt index 78dbd94f7..ef397bdd8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Core3_1.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt index 78dbd94f7..ef397bdd8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet6_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt index 78dbd94f7..ef397bdd8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.DotNet7_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt index 78dbd94f7..ef397bdd8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.Net4_8.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt index 78dbd94f7..ef397bdd8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Int.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt index c8f5507a2..82026ab16 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Core3_1.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt index c8f5507a2..82026ab16 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet6_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt index c8f5507a2..82026ab16 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.DotNet7_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt index c8f5507a2..82026ab16 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.Net4_8.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt index c8f5507a2..82026ab16 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Long.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt index c1043b288..875ca2bdf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Core3_1.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt index c1043b288..875ca2bdf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet6_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt index c1043b288..875ca2bdf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.DotNet7_0.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt index c1043b288..875ca2bdf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.Net4_8.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt index c1043b288..875ca2bdf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=MassTransitNewId.verified.txt @@ -22,6 +22,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt index 0ba9eeb7d..898bacee6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Core3_1.verified.txt @@ -23,6 +23,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt index 0ba9eeb7d..898bacee6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet6_0.verified.txt @@ -23,6 +23,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt index 0ba9eeb7d..898bacee6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.DotNet7_0.verified.txt @@ -23,6 +23,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt index 0ba9eeb7d..898bacee6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.Net4_8.verified.txt @@ -23,6 +23,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt index 0ba9eeb7d..898bacee6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=NullableString.verified.txt @@ -23,6 +23,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt index d4f5ed091..672589af9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Core3_1.verified.txt @@ -22,6 +22,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt index d4f5ed091..672589af9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet6_0.verified.txt @@ -22,6 +22,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt index d4f5ed091..672589af9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.DotNet7_0.verified.txt @@ -22,6 +22,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt index d4f5ed091..672589af9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.Net4_8.verified.txt @@ -22,6 +22,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt index d4f5ed091..672589af9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=String.verified.txt @@ -22,6 +22,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt index c7965c54d..95ab1cbb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index c7965c54d..95ab1cbb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index c7965c54d..95ab1cbb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt index c7965c54d..95ab1cbb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt index c7965c54d..95ab1cbb9 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=DapperTypeHandler_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index 508208c37..5c8b31538 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index 508208c37..5c8b31538 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index 508208c37..5c8b31538 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index 508208c37..5c8b31538 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt index 508208c37..5c8b31538 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=EfCoreValueConverter_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt index db59f66c1..6dc2c9809 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index db59f66c1..6dc2c9809 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index db59f66c1..6dc2c9809 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt index db59f66c1..6dc2c9809 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt index db59f66c1..6dc2c9809 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=NewtonsoftJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt index bef90429e..c05105d8b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt index bef90429e..c05105d8b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt index bef90429e..c05105d8b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt index bef90429e..c05105d8b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt index bef90429e..c05105d8b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IComparable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt index a13e9bec6..298a9ab68 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt index a13e9bec6..298a9ab68 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt index a13e9bec6..298a9ab68 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt index a13e9bec6..298a9ab68 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt index a13e9bec6..298a9ab68 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IEquatable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt index e94e1a2ac..4eace68dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt index e94e1a2ac..4eace68dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt index e94e1a2ac..4eace68dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt index e94e1a2ac..4eace68dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt index e94e1a2ac..4eace68dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=IParsable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt index fad5ea0b5..7bd7298ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt index fad5ea0b5..7bd7298ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt index fad5ea0b5..7bd7298ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt index fad5ea0b5..7bd7298ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt index fad5ea0b5..7bd7298ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=None_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index f72224715..7433dc1ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index f72224715..7433dc1ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index f72224715..7433dc1ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index f72224715..7433dc1ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt index f72224715..7433dc1ec 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SwaggerSchemaFilter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt index d6d801a99..657eee50a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt index d6d801a99..657eee50a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt index d6d801a99..657eee50a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt index d6d801a99..657eee50a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt index d6d801a99..657eee50a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=SystemTextJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt index 295e92baf..ec9fe7152 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt index 295e92baf..ec9fe7152 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt index 295e92baf..ec9fe7152 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt index 295e92baf..ec9fe7152 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt index 295e92baf..ec9fe7152 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Guid_c=TypeConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 5ed784d4a..1a359ab35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 5ed784d4a..1a359ab35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 5ed784d4a..1a359ab35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 5ed784d4a..1a359ab35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt index 5ed784d4a..1a359ab35 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=DapperTypeHandler_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index d3e50467b..4538584cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index d3e50467b..4538584cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index d3e50467b..4538584cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index d3e50467b..4538584cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt index d3e50467b..4538584cf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=EfCoreValueConverter_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt index b4d9738e7..a9d0a0884 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index b4d9738e7..a9d0a0884 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index b4d9738e7..a9d0a0884 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt index b4d9738e7..a9d0a0884 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt index b4d9738e7..a9d0a0884 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=NewtonsoftJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt index d76d3afd2..f7b93a1a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt index d76d3afd2..f7b93a1a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt index d76d3afd2..f7b93a1a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt index d76d3afd2..f7b93a1a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt index d76d3afd2..f7b93a1a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IComparable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt index 5d23b64a1..71ecb8822 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt index 5d23b64a1..71ecb8822 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt index 5d23b64a1..71ecb8822 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt index 5d23b64a1..71ecb8822 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt index 5d23b64a1..71ecb8822 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IEquatable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt index 48b56d13e..d64a059e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt index 48b56d13e..d64a059e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt index 48b56d13e..d64a059e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt index 48b56d13e..d64a059e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt index 48b56d13e..d64a059e3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=IParsable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt index 45272d34a..83b72d9c3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt index 45272d34a..83b72d9c3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt index 45272d34a..83b72d9c3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt index 45272d34a..83b72d9c3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt index 45272d34a..83b72d9c3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=None_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index 297090ba1..6d5900132 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index 297090ba1..6d5900132 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index 297090ba1..6d5900132 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index 297090ba1..6d5900132 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt index 297090ba1..6d5900132 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SwaggerSchemaFilter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt index 7c016c3be..b31b2b527 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt index 7c016c3be..b31b2b527 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt index 7c016c3be..b31b2b527 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt index 7c016c3be..b31b2b527 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt index 7c016c3be..b31b2b527 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=SystemTextJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt index 39f1e9331..fe1551202 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt index 39f1e9331..fe1551202 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt index 39f1e9331..fe1551202 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt index 39f1e9331..fe1551202 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt index 39f1e9331..fe1551202 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Int_c=TypeConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt index b62d70add..6d9709fa1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index b62d70add..6d9709fa1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index b62d70add..6d9709fa1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt index b62d70add..6d9709fa1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt index b62d70add..6d9709fa1 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=DapperTypeHandler_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index cb5754863..9f14b9ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index cb5754863..9f14b9ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index cb5754863..9f14b9ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index cb5754863..9f14b9ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt index cb5754863..9f14b9ac7 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=EfCoreValueConverter_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt index 7052a3b27..e6ebafd65 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index 7052a3b27..e6ebafd65 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index 7052a3b27..e6ebafd65 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt index 7052a3b27..e6ebafd65 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt index 7052a3b27..e6ebafd65 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=NewtonsoftJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt index c38fa63f6..16e1e540f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt index c38fa63f6..16e1e540f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt index c38fa63f6..16e1e540f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt index c38fa63f6..16e1e540f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt index c38fa63f6..16e1e540f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IComparable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt index 13b9b1ac7..10c29a473 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt index 13b9b1ac7..10c29a473 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt index 13b9b1ac7..10c29a473 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt index 13b9b1ac7..10c29a473 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt index 13b9b1ac7..10c29a473 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IEquatable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt index 45dac2ba8..023858bcd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt index 45dac2ba8..023858bcd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt index 45dac2ba8..023858bcd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt index 45dac2ba8..023858bcd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt index 45dac2ba8..023858bcd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=IParsable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt index af1658c35..bf54ff265 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt index af1658c35..bf54ff265 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt index af1658c35..bf54ff265 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt index af1658c35..bf54ff265 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt index af1658c35..bf54ff265 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=None_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index 72b024dca..61475fdf2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index 72b024dca..61475fdf2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index 72b024dca..61475fdf2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index 72b024dca..61475fdf2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt index 72b024dca..61475fdf2 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SwaggerSchemaFilter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt index 17a45333f..c7e7acc44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt index 17a45333f..c7e7acc44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt index 17a45333f..c7e7acc44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt index 17a45333f..c7e7acc44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt index 17a45333f..c7e7acc44 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=SystemTextJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt index e22d0478c..04b427147 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt index e22d0478c..04b427147 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt index e22d0478c..04b427147 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt index e22d0478c..04b427147 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt index e22d0478c..04b427147 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=Long_c=TypeConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(0); public bool Equals(MyTestId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 6b5b8702d..a6f4c14a8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 6b5b8702d..a6f4c14a8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 6b5b8702d..a6f4c14a8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 6b5b8702d..a6f4c14a8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt index 6b5b8702d..a6f4c14a8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=DapperTypeHandler_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index 9114f2d54..516ad6621 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index 9114f2d54..516ad6621 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index 9114f2d54..516ad6621 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index 9114f2d54..516ad6621 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt index 9114f2d54..516ad6621 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=EfCoreValueConverter_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt index 181d85e44..4e3b7d682 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index 181d85e44..4e3b7d682 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index 181d85e44..4e3b7d682 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt index 181d85e44..4e3b7d682 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt index 181d85e44..4e3b7d682 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=NewtonsoftJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt index 3a19fc65e..6f9e66a60 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt index 3a19fc65e..6f9e66a60 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt index 3a19fc65e..6f9e66a60 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt index 3a19fc65e..6f9e66a60 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt index 3a19fc65e..6f9e66a60 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IComparable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt index b4c2d5867..7f737b58a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt index b4c2d5867..7f737b58a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt index b4c2d5867..7f737b58a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt index b4c2d5867..7f737b58a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt index b4c2d5867..7f737b58a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IEquatable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt index f71234e03..d899e03df 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt index f71234e03..d899e03df 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt index f71234e03..d899e03df 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt index f71234e03..d899e03df 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt index f71234e03..d899e03df 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=IParsable.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt index 7e4892f41..b269a6f5c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt index 7e4892f41..b269a6f5c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt index 7e4892f41..b269a6f5c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt index 7e4892f41..b269a6f5c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt index 7e4892f41..b269a6f5c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=None_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index 699828755..dd6ee0e3d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index 699828755..dd6ee0e3d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index 699828755..dd6ee0e3d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index 699828755..dd6ee0e3d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt index 699828755..dd6ee0e3d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SwaggerSchemaFilter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt index 3de0600ab..9b6a12ba4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt index 3de0600ab..9b6a12ba4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt index 3de0600ab..9b6a12ba4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt index 3de0600ab..9b6a12ba4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt index 3de0600ab..9b6a12ba4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=SystemTextJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt index 757eb4ebb..ca57c53a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt index 757eb4ebb..ca57c53a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt index 757eb4ebb..ca57c53a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt index 757eb4ebb..ca57c53a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt index 757eb4ebb..ca57c53a6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=MassTransitNewId_c=TypeConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(MassTransit.NewId.Next()); public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 158253dea..71d558a1a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 158253dea..71d558a1a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 158253dea..71d558a1a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 158253dea..71d558a1a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt index 158253dea..71d558a1a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=DapperTypeHandler_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index e1a174104..99739c312 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index e1a174104..99739c312 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index e1a174104..99739c312 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index e1a174104..99739c312 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt index e1a174104..99739c312 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=EfCoreValueConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt index 9660c1fc0..e7039bc1c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index 9660c1fc0..e7039bc1c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index 9660c1fc0..e7039bc1c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt index 9660c1fc0..e7039bc1c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt index 9660c1fc0..e7039bc1c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=NewtonsoftJson_i=None.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt index d779d1af4..bac7f46ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt index d779d1af4..bac7f46ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt index d779d1af4..bac7f46ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt index d779d1af4..bac7f46ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt index d779d1af4..bac7f46ea 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IComparable.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt index bb2e2c7d2..4f7e9865c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt index bb2e2c7d2..4f7e9865c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt index bb2e2c7d2..4f7e9865c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt index bb2e2c7d2..4f7e9865c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt index bb2e2c7d2..4f7e9865c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IEquatable.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt index cb8f66e2d..60a9d1907 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt index cb8f66e2d..60a9d1907 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt index cb8f66e2d..60a9d1907 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt index cb8f66e2d..60a9d1907 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt index cb8f66e2d..60a9d1907 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=IParsable.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt index fe1e43665..64c0520a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt index fe1e43665..64c0520a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt index fe1e43665..64c0520a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt index fe1e43665..64c0520a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt index fe1e43665..64c0520a3 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=None_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index c85338e9a..e0e53762f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index c85338e9a..e0e53762f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index c85338e9a..e0e53762f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index c85338e9a..e0e53762f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt index c85338e9a..e0e53762f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SwaggerSchemaFilter_i=None.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt index c049fb7f5..64c8a2195 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt index c049fb7f5..64c8a2195 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt index c049fb7f5..64c8a2195 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt index c049fb7f5..64c8a2195 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt index c049fb7f5..64c8a2195 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=SystemTextJson_i=None.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt index 50b3c0585..52070ac2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Core3_1.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt index 50b3c0585..52070ac2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt index 50b3c0585..52070ac2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt index 50b3c0585..52070ac2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.Net4_8.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt index 50b3c0585..52070ac2a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=NullableString_c=TypeConverter_i=None.verified.txt @@ -20,6 +20,10 @@ Value = value; } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt index 80f82650a..67b1ce8c8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt index 80f82650a..67b1ce8c8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt index 80f82650a..67b1ce8c8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt index 80f82650a..67b1ce8c8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt index 80f82650a..67b1ce8c8 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=DapperTypeHandler_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt index 05700f78d..da60d2fe0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt index 05700f78d..da60d2fe0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt index 05700f78d..da60d2fe0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt index 05700f78d..da60d2fe0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt index 05700f78d..da60d2fe0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=EfCoreValueConverter_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt index d7596bf2b..2fe8b1fc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt index d7596bf2b..2fe8b1fc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt index d7596bf2b..2fe8b1fc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt index d7596bf2b..2fe8b1fc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt index d7596bf2b..2fe8b1fc6 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=NewtonsoftJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt index 4fae5139a..7c47a4192 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt index 4fae5139a..7c47a4192 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt index 4fae5139a..7c47a4192 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt index 4fae5139a..7c47a4192 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt index 4fae5139a..7c47a4192 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IComparable.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt index 050bcc20b..e167942a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt index 050bcc20b..e167942a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt index 050bcc20b..e167942a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt index 050bcc20b..e167942a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt index 050bcc20b..e167942a4 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IEquatable.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt index ea5cbe4e3..ba5c87baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt index ea5cbe4e3..ba5c87baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt index ea5cbe4e3..ba5c87baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt index ea5cbe4e3..ba5c87baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt index ea5cbe4e3..ba5c87baf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=IParsable.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt index 0987c7d64..300f67897 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Core3_1.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt index 0987c7d64..300f67897 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet6_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt index 0987c7d64..300f67897 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.DotNet7_0.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt index 0987c7d64..300f67897 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.Net4_8.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt index 0987c7d64..300f67897 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=None_i=None.verified.txt @@ -18,6 +18,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt index 6e4590319..7ca7adca5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt index 6e4590319..7ca7adca5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt index 6e4590319..7ca7adca5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt index 6e4590319..7ca7adca5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt index 6e4590319..7ca7adca5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SwaggerSchemaFilter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt index 1396ccae3..eaf28933d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt index 1396ccae3..eaf28933d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt index 1396ccae3..eaf28933d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt index 1396ccae3..eaf28933d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt index 1396ccae3..eaf28933d 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=SystemTextJson_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt index d35ac20a3..174e71a6b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Core3_1.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt index d35ac20a3..174e71a6b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet6_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt index d35ac20a3..174e71a6b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.DotNet7_0.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt index d35ac20a3..174e71a6b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.Net4_8.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt index d35ac20a3..174e71a6b 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_type=String_c=TypeConverter_i=None.verified.txt @@ -19,6 +19,10 @@ Value = value ?? throw new System.ArgumentNullException(nameof(value)); } + public MyTestId() + { + } + public static readonly MyTestId Empty = new MyTestId(string.Empty); public bool Equals(MyTestId other) diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt index ff61cdde7..43fb24c8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Core3_1.verified.txt @@ -23,6 +23,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt index ff61cdde7..43fb24c8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet6_0.verified.txt @@ -23,6 +23,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt index ff61cdde7..43fb24c8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.DotNet7_0.verified.txt @@ -23,6 +23,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt index ff61cdde7..43fb24c8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.Net4_8.verified.txt @@ -23,6 +23,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt index ff61cdde7..43fb24c8f 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=0.verified.txt @@ -23,6 +23,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt index dacf3158c..e87cb15bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Core3_1.verified.txt @@ -25,6 +25,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt index dacf3158c..e87cb15bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet6_0.verified.txt @@ -25,6 +25,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt index dacf3158c..e87cb15bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.DotNet7_0.verified.txt @@ -25,6 +25,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt index dacf3158c..e87cb15bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.Net4_8.verified.txt @@ -25,6 +25,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt index dacf3158c..e87cb15bf 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=1.verified.txt @@ -25,6 +25,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt index b71458e7e..9867823d0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Core3_1.verified.txt @@ -27,6 +27,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt index b71458e7e..9867823d0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet6_0.verified.txt @@ -27,6 +27,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt index b71458e7e..9867823d0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.DotNet7_0.verified.txt @@ -27,6 +27,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt index b71458e7e..9867823d0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.Net4_8.verified.txt @@ -27,6 +27,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt index b71458e7e..9867823d0 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdWithNestedClassCorrectly_nestedClassCount=2.verified.txt @@ -27,6 +27,10 @@ namespace MyTestNamespace Value = value; } + public MyTestId() + { + } + public static MyTestId New() => new MyTestId(System.Guid.NewGuid()); public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt index 56be7f36f..4b1b6e2eb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Core3_1.verified.txt @@ -251,6 +251,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt index 56be7f36f..4b1b6e2eb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet6_0.verified.txt @@ -251,6 +251,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt index 56be7f36f..4b1b6e2eb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.DotNet7_0.verified.txt @@ -251,6 +251,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt index 56be7f36f..4b1b6e2eb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.Net4_8.verified.txt @@ -251,6 +251,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt index 56be7f36f..4b1b6e2eb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateDefaultIdInGlobalNamespace.verified.txt @@ -251,6 +251,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInFileScopedNamespace.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt index 1d8786678..b85dc5507 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdInNamespace.verified.txt @@ -253,6 +253,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithNamedParameters_backingType=Guid_converter=null.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt index 0e88633ad..ce6162e7c 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson, SystemTextJson.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt index 8a5c7e797..f06762edb 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=NewtonsoftJson.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt index 24997c508..80f2b5c33 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=SystemTextJson.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Core3_1.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet6_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.DotNet7_0.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.Net4_8.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt index 839a3cdf0..53c4a3a3e 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=TypeConverter.verified.txt @@ -252,6 +252,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt index c5dd24327..816a481dd 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateIdWithPositionalParameters_backingType=Guid_converter=null.verified.txt @@ -253,6 +253,10 @@ namespace MyTests.TestNameSpace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt index 1d386be5d..a4df06dc5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Core3_1.verified.txt @@ -253,6 +253,10 @@ namespace MyContracts.V1 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); @@ -357,6 +361,10 @@ namespace MyContracts.V2 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt index 1d386be5d..a4df06dc5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet6_0.verified.txt @@ -253,6 +253,10 @@ namespace MyContracts.V1 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); @@ -357,6 +361,10 @@ namespace MyContracts.V2 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt index 1d386be5d..a4df06dc5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.DotNet7_0.verified.txt @@ -253,6 +253,10 @@ namespace MyContracts.V1 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); @@ -357,6 +361,10 @@ namespace MyContracts.V2 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt index 1d386be5d..a4df06dc5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.Net4_8.verified.txt @@ -253,6 +253,10 @@ namespace MyContracts.V1 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); @@ -357,6 +361,10 @@ namespace MyContracts.V2 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt index 1d386be5d..a4df06dc5 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateMultipleIdsWithSameName.verified.txt @@ -253,6 +253,10 @@ namespace MyContracts.V1 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); @@ -357,6 +361,10 @@ namespace MyContracts.V2 Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt index 91d1a1543..f3387af08 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -255,6 +255,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index 91d1a1543..f3387af08 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -255,6 +255,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index 91d1a1543..f3387af08 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -255,6 +255,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt index 91d1a1543..f3387af08 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -255,6 +255,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt index 91d1a1543..f3387af08 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateNestedIdInFileScopeNamespace.verified.txt @@ -255,6 +255,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt index 82c6f9f8d..32b19a191 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Core3_1.verified.txt @@ -259,6 +259,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt index 82c6f9f8d..32b19a191 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet6_0.verified.txt @@ -259,6 +259,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt index 82c6f9f8d..32b19a191 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.DotNet7_0.verified.txt @@ -259,6 +259,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt index 82c6f9f8d..32b19a191 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.Net4_8.verified.txt @@ -259,6 +259,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt index 82c6f9f8d..32b19a191 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanGenerateVeryNestedIdInFileScopeNamespace.verified.txt @@ -259,6 +259,10 @@ namespace SomeNamespace Value = value; } + public MyId() + { + } + public static MyId New() => new MyId(System.Guid.NewGuid()); public static readonly MyId Empty = new MyId(System.Guid.Empty); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt index e53221f19..0c614944a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Core3_1.verified.txt @@ -249,6 +249,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static readonly MyId Empty = new MyId(0); public bool Equals(MyId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt index e53221f19..0c614944a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet6_0.verified.txt @@ -249,6 +249,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static readonly MyId Empty = new MyId(0); public bool Equals(MyId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt index e53221f19..0c614944a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.DotNet7_0.verified.txt @@ -249,6 +249,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static readonly MyId Empty = new MyId(0); public bool Equals(MyId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt index e53221f19..0c614944a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.Net4_8.verified.txt @@ -249,6 +249,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static readonly MyId Empty = new MyId(0); public bool Equals(MyId other) => this.Value.Equals(other.Value); diff --git a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt index e53221f19..0c614944a 100644 --- a/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt +++ b/test/StronglyTypedIds.Tests/Snapshots/StronglyTypedIdGeneratorTests.CanOverrideDefaultsUsingGlobalAttribute.verified.txt @@ -249,6 +249,10 @@ namespace StronglyTypedIds Value = value; } + public MyId() + { + } + public static readonly MyId Empty = new MyId(0); public bool Equals(MyId other) => this.Value.Equals(other.Value); diff --git a/version.props b/version.props index ee9424be0..8de93cda4 100644 --- a/version.props +++ b/version.props @@ -1,6 +1,6 @@ - 1.0.18 + 1.0.19 $(VersionPrefix) $(VersionPrefix)-$(VersionSuffix)